fix(compiler): 修复对象::class获取类名

pull/7/head
Yurun 2 months ago
parent df5dd2a5f6
commit b6e937a4cc
  1. 8
      src/Php/CompilerBase.php
  2. 42
      tests/aot/class/get-object-class.phpt

@ -6257,10 +6257,18 @@ class CompilerBase extends \PhpAot\Core\Translator implements PropertyAccessCont
}
}
if ($self or $this->isNameExpr($expr->class)) {
$class = $this->getNamespacedClassName($class);
}
if ($const === '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)) {
$classDef = $this->getClass($class);

@ -0,0 +1,42 @@
--TEST--
get_class() and $object::class should return original class name (case-sensitive with namespace)
--FILE--
<?php
namespace NS {
class Test1
{
}
}
namespace {
use NS\Test1;
class Test2
{
}
function main() {
$test1 = new NS\Test1;
var_dump(get_class($test1));
var_dump($test1::class);
$test1 = new Test1;
var_dump(get_class($test1));
var_dump($test1::class);
$test2 = new Test2;
var_dump(get_class($test2));
var_dump($test2::class);
}
}
?>
--EXPECT--
string(8) "NS\Test1"
string(8) "NS\Test1"
string(8) "NS\Test1"
string(8) "NS\Test1"
string(5) "Test2"
string(5) "Test2"
Loading…
Cancel
Save