- 在编译器中为匿名类继承的父类添加全限定名称转换 - 修复了当匿名类继承使用use导入的类时的名称解析错误 - 添加了对继承类名的命名空间处理逻辑 - 确保匿名类能够正确继承并访问父类方法pull/1/head
parent
9d9556929f
commit
1567ad2f88
3 changed files with 40 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||||||
|
--TEST-- |
||||||
|
Anonymous Classes - Runtime class definition |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
namespace TestApp { |
||||||
|
class Greeter { |
||||||
|
protected string $greeting; |
||||||
|
|
||||||
|
public function __construct(string $greeting) { |
||||||
|
$this->greeting = $greeting; |
||||||
|
} |
||||||
|
|
||||||
|
public function greet() { |
||||||
|
return $this->greeting; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
namespace { |
||||||
|
use TestApp\Greeter; |
||||||
|
function main() { |
||||||
|
$class = new class("Hello") extends Greeter { |
||||||
|
public function greet() { |
||||||
|
return "{$this->greeting} from anonymous class"; |
||||||
|
} |
||||||
|
}; |
||||||
|
echo $class->greet(), "\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
Hello from anonymous class |
||||||
Loading…
Reference in new issue