diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 36ab3cbe..2bd65923 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -643,13 +643,16 @@ class CompilerBase extends \PhpAot\Core\Translator protected function getNativeName(string $fn, string $ns = '', string $class = ''): string { + $names = []; if ($ns) { $names[] = $this->escapeNamespace($ns); } if ($class) { $names[] = $this->escapeClass($class); } - $names[] = $this->escapeName($fn); + if ($fn) { + $names[] = $this->escapeName($fn); + } return implode(self::NAMESPACE_SEPARATOR, $names); } @@ -1452,6 +1455,9 @@ class CompilerBase extends \PhpAot\Core\Translator */ protected function hasNativeClass(string $name): bool { + if (!str_starts_with($name, 'Test')) { + debug_print_backtrace(); + } return array_key_exists($this->escapeClass($name), $this->classes); } @@ -3360,7 +3366,7 @@ class CompilerBase extends \PhpAot\Core\Translator return $id; } if ($id === 'self') { - $id = $this->classDef->getNamespacedName(false); + $id = $this->getNamespacedClassName($this->class); } if ($this->isNameExpr($node) or $this->isIdExpr($node)) { return $this->genCharPtr($id, true); @@ -3441,11 +3447,12 @@ class CompilerBase extends \PhpAot\Core\Translator $class = $this->class; } - if (!$this->hasNativeClass($class)) { + $fullName = $this->getNamespacedClassName($class); + if (!$this->hasNativeClass($fullName)) { return null; } - $classDef = $this->classes[$class]; + $classDef = $this->getClassDef($fullName); $namespace = $classDef->namespace; if ($classDef->hasProperty($prop)) { $propDef = $classDef->getProperty($prop); @@ -3500,7 +3507,7 @@ class CompilerBase extends \PhpAot\Core\Translator { $nativeProp = $this->findNativeStaticProperty($expr, $class, $namespace); if ($nativeProp) { - $classPtr = $this->getClassEntryPtr($class); + $classPtr = $this->getClassEntryPtr($this->getNamespacedClassName($class)); $propOffset = self::PREFIX . $this->getPropertyOffset($nativeProp->name, $class, $namespace); return 'php::getStaticProperty(' . $classPtr . ', ' . $propOffset . ')'; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 3eaf752f..edebf6a8 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -690,12 +690,12 @@ class Translator extends Preprocessor $extends = $class->extends; } - $nativeName = $this->getNativeName('', $this->class, $this->namespace); - if ($this->hasNativeClass($nativeName)) { - $this->classDef = $this->classes[$nativeName]; + $fullName = $this->getNamespacedClassName($this->class); + if ($this->hasNativeClass($fullName)) { + $this->classDef = $this->classes[$fullName]; } else { $this->classDef = new ClassDef($this->class, $flags, $this->namespace); - $this->addClass($nativeName, $this->classDef); + $this->addClass($fullName, $this->classDef); } if ($class instanceof Node\Stmt\Enum_) { @@ -817,7 +817,7 @@ class Translator extends Preprocessor $prop->class = $classDef->getNamespacedName(false); $prop->name = $property->name; $prop->default = $property->default; - $this->staticPropertyList[] = $prop; + $this->staticPropertyList[$name . '::' . $property->name] = $prop; } else { $propOffset = self::PREFIX . $this->getPropertyOffset($property->name, $classDef->name, $classDef->namespace); $cppCode .= $this->getIndent() . 'this_.attr(' . $propOffset . ') = ' . $property->default . ';' . PHP_EOL;