- 在 CompilerBase 中添加 Scalar_MagicConst_Trait 的解析支持 - 为 __TRAIT__ 常量实现作用域检查逻辑 - 为 __CLASS__ 常量添加 trait 环境下的返回逻辑 - 在 Preprocessor 中添加类属性钩子不支持的错误提示 - 添加 trait 魔术常量的功能测试用例 - 更新 trait 示例代码以展示魔术常量使用pull/1/head
parent
37bfc24432
commit
5bf12a10ed
5 changed files with 74 additions and 2 deletions
@ -0,0 +1,24 @@ |
||||
<?php |
||||
class Example |
||||
{ |
||||
private bool $modified = false; |
||||
|
||||
public string $foo = 'default value' { |
||||
get { |
||||
if ($this->modified) { |
||||
return $this->foo . ' (modified)'; |
||||
} |
||||
return $this->foo; |
||||
} |
||||
set(string $value) { |
||||
$this->foo = strtolower($value); |
||||
$this->modified = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$example = new Example(); |
||||
$example->foo = 'Hello World'; |
||||
} |
||||
@ -0,0 +1,28 @@ |
||||
--TEST-- |
||||
trait full class name |
||||
--FILE-- |
||||
<?php |
||||
trait TraitA { |
||||
public function sayHello() { |
||||
var_dump(__TRAIT__); |
||||
var_dump(__CLASS__); |
||||
} |
||||
} |
||||
|
||||
class MyHelloWorld |
||||
{ |
||||
use TraitA; |
||||
public function sayHelloWorld() { |
||||
$this->sayHello(); |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$obj = new MyHelloWorld(); |
||||
$obj->sayHelloWorld(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(6) "TraitA" |
||||
string(12) "MyHelloWorld" |
||||
Loading…
Reference in new issue