- 实现了 Trait 的基本语法解析和处理功能 - 添加了 trait 属性、方法、常量的继承机制 - 实现了 trait 使用时的命名空间解析 - 添加了类与 trait 同名成员的冲突处理逻辑 - 新增 trait 相关的测试用例 - 重构了类定义结构以支持 trait 类型判断pull/1/head
parent
f4b8d6c1f3
commit
88693dcc21
6 changed files with 96 additions and 2 deletions
@ -0,0 +1,40 @@ |
||||
--TEST-- |
||||
Single Trait with simple trait method |
||||
--FILE-- |
||||
<?php |
||||
trait THello { |
||||
protected string $name = 'world'; |
||||
static public int $count = 0; |
||||
public const BAZ = 'baz'; |
||||
|
||||
public function hello() { |
||||
echo 'Hello ' . $this->name . PHP_EOL; |
||||
$this->foo(); |
||||
} |
||||
|
||||
public function foo(): void { |
||||
$array = [ |
||||
'count' => self::$count, |
||||
'baz' => self::BAZ, |
||||
]; |
||||
var_dump($array); |
||||
} |
||||
} |
||||
|
||||
class TraitsTest { |
||||
use THello; |
||||
} |
||||
|
||||
function main() { |
||||
$test = new TraitsTest(); |
||||
$test->hello(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
Hello world |
||||
array(2) { |
||||
["count"]=> |
||||
int(0) |
||||
["baz"]=> |
||||
string(3) "baz" |
||||
} |
||||
@ -0,0 +1,17 @@ |
||||
--TEST-- |
||||
Single Trait with simple trait method |
||||
--FILE-- |
||||
<?php |
||||
trait HelloTrait { |
||||
public $name = 'world'; |
||||
public function hello() { |
||||
echo 'Hello ' . $this->name . PHP_EOL; |
||||
} |
||||
} |
||||
|
||||
function main() { |
||||
eval("(new class { use HelloTrait;})->hello();"); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
Hello world |
||||
Loading…
Reference in new issue