From b6e937a4ccd482ed9a6f475a45023fe494cfe59a Mon Sep 17 00:00:00 2001 From: Yurun Date: Thu, 2 Jul 2026 20:14:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1::class=E8=8E=B7=E5=8F=96=E7=B1=BB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Php/CompilerBase.php | 12 ++++++-- tests/aot/class/get-object-class.phpt | 42 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/aot/class/get-object-class.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index c216b715..38dbdab8 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -6257,9 +6257,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"