diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index c68d8b17..2e17335a 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -6341,9 +6341,17 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont } } - $class = $this->getNamespacedClassName($class); + if ($self or $this->isNameExpr($expr->class)) { + $class = $this->getNamespacedClassName($class); + } if ($const === 'class') { - return $this->getLiteralString($class); + if ($self or $this->isNameExpr($expr->class)) { + return $this->getLiteralString($class); + } + if ($this->isVarExpr($expr->class) and $this->isTypedObject($expr->class->name)) { + return $this->getLiteralString($this->getObjectType($expr->class->name)); + } + return 'php::fn::get_class(' . $class . ')'; } if (($self or $this->isNameExpr($expr->class)) and $this->isIdExpr($expr->name)) { if ($this->hasClass($class)) { diff --git a/tests/aot/class/get-object-class.phpt b/tests/aot/class/get-object-class.phpt new file mode 100644 index 00000000..38cb9e21 --- /dev/null +++ b/tests/aot/class/get-object-class.phpt @@ -0,0 +1,42 @@ +--TEST-- +get_class() and $object::class should return original class name (case-sensitive with namespace) +--FILE-- + +--EXPECT-- +string(8) "NS\Test1" +string(8) "NS\Test1" +string(8) "NS\Test1" +string(8) "NS\Test1" +string(5) "Test2" +string(5) "Test2"