diff --git a/phpunit/code/get-parent-class-internal-literal.php b/phpunit/code/get-parent-class-internal-literal.php new file mode 100644 index 00000000..0a891211 --- /dev/null +++ b/phpunit/code/get-parent-class-internal-literal.php @@ -0,0 +1,13 @@ +addFiles([$source]); + $compiler->prepareFile($source); + $cpp = file_get_contents($compiler->convertFile($source)); + + self::assertIsString($cpp); + self::assertSame(2, substr_count($cpp, 'php::fn::get_parent_class(')); + } +} diff --git a/src/Optimizer/FuncCallOptimizer.php b/src/Optimizer/FuncCallOptimizer.php index 54e030e8..ff875447 100644 --- a/src/Optimizer/FuncCallOptimizer.php +++ b/src/Optimizer/FuncCallOptimizer.php @@ -965,7 +965,7 @@ protected function genGetParentClass(string $n, Node\Expr\FuncCall $e, array $c) ); } if ($this->isScalarString($arg)) { - $cls = $this->getClass($arg->value); + $cls = $this->getClassDef($arg->value); if ($cls && $cls->extends) return $this->getLiteralString($cls->extends); if ($cls && !$cls->extends) return 'false'; } diff --git a/tests/std/core/006_get_parent_class.phpt b/tests/std/core/006_get_parent_class.phpt index 982a5300..df83ec54 100644 --- a/tests/std/core/006_get_parent_class.phpt +++ b/tests/std/core/006_get_parent_class.phpt @@ -16,6 +16,8 @@ function main() { echo get_parent_class(Child::class) === "Base" ? "ok-cls\n" : "fail-cls\n"; echo get_parent_class($noParent) === false ? "ok-obj-false\n" : "fail-obj-false\n"; echo get_parent_class(NoParent::class) === false ? "ok-cls-false\n" : "fail-cls-false\n"; + echo get_parent_class('RuntimeException') === "Exception" ? "ok-internal-cls\n" : "fail-internal-cls\n"; + echo get_parent_class('Exception') === false ? "ok-internal-cls-false\n" : "fail-internal-cls-false\n"; echo "done\n"; } @@ -26,4 +28,6 @@ ok-obj ok-cls ok-obj-false ok-cls-false +ok-internal-cls +ok-internal-cls-false done