- 添加__call、__invoke、__toString、__debugInfo等魔术方法测试用例 - 添加__callStatic静态魔术方法支持和测试用例 - 在ClassDef中实现方法名称大小写不敏感的查找机制 - 添加DynamicCall异常用于处理动态方法调用场景 - 改进编译器对__call和__callStatic魔术方法的识别和处理 - 优化方法调用流程以支持动态方法分派机制 - 更新方法注册逻辑使用addMethod方法替代直接赋值操作pull/1/head
parent
a4bc4fcfc0
commit
55caa1fcef
6 changed files with 120 additions and 14 deletions
@ -0,0 +1,7 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace PhpAot\Php\Exception; |
||||||
|
|
||||||
|
class DynamicCall extends \RuntimeException |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
--TEST-- |
||||||
|
Magic Methods - __get, __set, __call, __invoke etc. |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class MagicClass { |
||||||
|
public static function __CallStatic(string $name, array $arguments): mixed { |
||||||
|
return "Called static method: {$name} with args: " . implode(', ', $arguments); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
var_dump(MagicClass::staticMethod('static1', 'static2')); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(62) "Called static method: staticMethod with args: static1, static2" |
||||||
@ -0,0 +1,52 @@ |
|||||||
|
--TEST-- |
||||||
|
Magic Methods - __get, __set, __call, __invoke etc. |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class MagicClass { |
||||||
|
// __call for instance methods |
||||||
|
public function __call(string $name, array $arguments): mixed { |
||||||
|
return "Called method: {$name} with args: " . implode(', ', $arguments); |
||||||
|
} |
||||||
|
|
||||||
|
// __invoke |
||||||
|
public function __invoke(mixed $value): mixed { |
||||||
|
return "Invoked with: {$value}"; |
||||||
|
} |
||||||
|
|
||||||
|
// __toString |
||||||
|
public function __toString(): string { |
||||||
|
return "MagicClass instance"; |
||||||
|
} |
||||||
|
|
||||||
|
// __debugInfo |
||||||
|
public function __debugInfo(): array { |
||||||
|
return ['custom' => 'debug info', 'data' => 'hello world']; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$magic = new MagicClass(); |
||||||
|
|
||||||
|
// Test __call |
||||||
|
var_dump($magic->someMethod('arg1', 'arg2')); |
||||||
|
|
||||||
|
// Test __invoke |
||||||
|
var_dump($magic('hello')); |
||||||
|
|
||||||
|
// Test __toString |
||||||
|
echo $magic . "\n"; |
||||||
|
|
||||||
|
// Test __debugInfo |
||||||
|
var_dump($magic); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(47) "Called method: someMethod with args: arg1, arg2" |
||||||
|
string(19) "Invoked with: hello" |
||||||
|
MagicClass instance |
||||||
|
object(MagicClass)#1 (2) { |
||||||
|
["custom"]=> |
||||||
|
string(10) "debug info" |
||||||
|
["data"]=> |
||||||
|
string(11) "hello world" |
||||||
|
} |
||||||
Loading…
Reference in new issue