diff --git a/src/Php/Preprocessor.php b/src/Php/Preprocessor.php index 0a57dd6e..51f06075 100644 --- a/src/Php/Preprocessor.php +++ b/src/Php/Preprocessor.php @@ -10,6 +10,7 @@ namespace PhpAot\Php; use PhpAot\Php\Exception\SyntaxError; use PhpParser\Node; +use PhpParser\NodeAbstract; use PhpParser\NodeFinder; use PhpParser\NodeTraverser; @@ -167,11 +168,20 @@ class Preprocessor extends CompilerBase } } + protected function getParentClass(NodeAbstract $extends): string + { + if ($extends instanceof Node\Name\FullyQualified) { + return $this->parseIdentifier($extends); + } else { + return $this->getNamespacedClassName($this->parseIdentifier($extends)); + } + } + protected function prepareClass(Node\Stmt\Class_|Node\Stmt\Trait_|Node\Stmt\Enum_ $class): string { $this->class = $this->parseIdentifier($class->name); if ($class->extends) { - $this->parentClass = $this->getNamespacedClassName($this->parseIdentifier($class->extends)); + $this->parentClass = $this->getParentClass($class->extends); $fullClassName = $this->getNamespacedClassName($this->class); $this->classExtends[$fullClassName] = $this->parentClass; } diff --git a/src/Php/Translator.php b/src/Php/Translator.php index a4e5da78..17857140 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -818,7 +818,7 @@ class Translator extends Preprocessor } if ($extends) { - $this->classDef->extends = $this->getNamespacedClassName($this->parseIdentifier($class->extends)); + $this->classDef->extends = $this->getParentClass($class->extends); if (isset($this->classes[$this->classDef->extends])) { $parent = $this->classes[$this->classDef->extends]; if ($parent->flags & Modifiers::FINAL) {