- 添加对 self::class、parent::class 和 static::class 的支持 - 实现 parent::class 的继承链验证和错误处理 - 禁止使用 static::class 并提示编译时无法解析 - 移除 objval() 函数中的冗余参数验证逻辑 - 为 self::class 和 parent::class 场景添加测试用例 - 更新版本号至 1064 - 添加 yield 示例代码文件pull/1/head
parent
d082de3f6e
commit
0647b6425a
6 changed files with 88 additions and 9 deletions
@ -0,0 +1,10 @@ |
||||
<?php |
||||
function fn_test_yeild() |
||||
{ |
||||
echo "第一次调用前\n"; |
||||
yield 1; // 产生值 1,并暂停 |
||||
echo "两次调用之间\n"; |
||||
yield 2; // 产生值 2,并暂停 |
||||
echo "最后一次调用后\n"; |
||||
yield 3; |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
<?php |
||||
|
||||
function main() |
||||
{ |
||||
require __DIR__ . '/fn.php'; |
||||
var_dump(fn_test_yeild()); |
||||
} |
||||
|
||||
@ -0,0 +1,24 @@ |
||||
--TEST-- |
||||
objval |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class Foo { |
||||
public function run($obj) { |
||||
$o = objval($obj, self::class); |
||||
$o->bar(); |
||||
} |
||||
|
||||
public function bar() { |
||||
var_dump(__METHOD__); |
||||
} |
||||
} |
||||
|
||||
function main() { |
||||
$o = new Foo(); |
||||
$o->run($o); |
||||
} |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
string(8) "Foo::bar" |
||||
@ -0,0 +1,32 @@ |
||||
--TEST-- |
||||
objval with parent::class |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class Base { |
||||
public function name(): string { |
||||
return 'Base'; |
||||
} |
||||
} |
||||
|
||||
class Child extends Base { |
||||
public function name(): string { |
||||
return 'Child'; |
||||
} |
||||
|
||||
public function castToParent($obj): Base { |
||||
return objval($obj, parent::class); |
||||
} |
||||
} |
||||
|
||||
function main() { |
||||
$b = new Base(); |
||||
$c = new Child(); |
||||
|
||||
$result = $c->castToParent($b); |
||||
var_dump($result->name()); |
||||
} |
||||
|
||||
?> |
||||
--EXPECT-- |
||||
string(4) "Base" |
||||
@ -1 +1 @@ |
||||
1063 |
||||
1064 |
||||
|
||||
Loading…
Reference in new issue