diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 91c678e4..569da39b 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -143,6 +143,7 @@ class CompilerBase extends \PhpAot\Core\Translator public const string DYNAMIC_CALLED_CLASS = '__dynamic_called_class__'; public const string STATIC_VAR = '_static_var_'; public const string GLOBAL_VAR = '_global_var_'; + public const string CONST_VAR = '_const_var_'; public const string OBJECT_PROP = '_object_prop_'; public const string CLASS_MAP = 'class_map'; public const string FUNC_MAP = 'func_map'; @@ -5021,22 +5022,22 @@ class CompilerBase extends \PhpAot\Core\Translator $constInfo->type = $this->detectStrValueType($value); $constInfo->namespace = $this->namespace; $constInfo->name = $name; - $this->constants[$this->escapeNamespace($name)] = $constInfo; + $this->constants[$this->escapeConstVar($name)] = $constInfo; } protected function hasConstant(string $name): bool { - return isset($this->constants[$this->escapeNamespace($name)]); + return isset($this->constants[$this->escapeConstVar($name)]); } protected function getConstant(string $name): string { - return $this->escapeNamespace($name); + return $this->escapeConstVar($name); } protected function getConstantType(string $name): string { - return $this->constants[$this->escapeNamespace($name)]->type; + return $this->constants[$this->escapeConstVar($name)]->type; } protected function detectStrValueType(mixed $constant): string diff --git a/src/Php/Generator/Utils.php b/src/Php/Generator/Utils.php index 89391995..284bcf8f 100644 --- a/src/Php/Generator/Utils.php +++ b/src/Php/Generator/Utils.php @@ -95,6 +95,11 @@ trait Utils return self::GLOBAL_VAR . $name; } + protected function escapeConstVar(string $name): string + { + return self::CONST_VAR . str_replace('\\', self::NAMESPACE_SEPARATOR, $name); + } + protected function escapeNamespace(string $ns): string { return str_replace('\\', self::NAMESPACE_SEPARATOR, strtolower($ns)); diff --git a/tests/aot/const/const-same-name.phpt b/tests/aot/const/const-same-name.phpt new file mode 100644 index 00000000..8a024fa3 --- /dev/null +++ b/tests/aot/const/const-same-name.phpt @@ -0,0 +1,15 @@ +--TEST-- +Constant with the same name (case-insensitive) resolve independently +--FILE-- + +--EXPECT-- +int(123) +int(456) diff --git a/tests/aot/const/const-var-same-name.phpt b/tests/aot/const/const-var-same-name.phpt new file mode 100644 index 00000000..28bf1a9c --- /dev/null +++ b/tests/aot/const/const-var-same-name.phpt @@ -0,0 +1,15 @@ +--TEST-- +Constant and variable with the same name (case-insensitive) resolve independently +--FILE-- + +--EXPECT-- +int(123) +int(456)