- 添加了对抽象方法调用的检查和处理逻辑 - 在方法指针获取时过滤掉抽象方法避免错误调用 - 对对象调用抽象类或接口方法时返回 false 避免运行时错误 - 添加了 noProgress 属性用于控制进度显示 - 完善了方法标志位检查机制防止虚方法调用异常pull/3/head
parent
0360a51104
commit
979ea385ca
2 changed files with 53 additions and 1 deletions
@ -0,0 +1,42 @@ |
|||||||
|
--TEST-- |
||||||
|
call abstract base method through concrete object |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
use native_types; |
||||||
|
|
||||||
|
abstract class Base |
||||||
|
{ |
||||||
|
abstract public function run(): string; |
||||||
|
} |
||||||
|
|
||||||
|
class Impl extends Base |
||||||
|
{ |
||||||
|
public function run(): string |
||||||
|
{ |
||||||
|
return 'ok'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function create(string $type): Base |
||||||
|
{ |
||||||
|
return match ($type) { |
||||||
|
'a' => new Impl(), |
||||||
|
default => new Impl(), |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): int |
||||||
|
{ |
||||||
|
$obj = create('a'); |
||||||
|
$r = $obj->run(); // ← CRASH 发生在此虚方法调用 |
||||||
|
echo "result: $r\n"; |
||||||
|
if ($r === 'ok') { |
||||||
|
echo "ALL OK\n"; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
return 1; |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
result: ok |
||||||
|
ALL OK |
||||||
Loading…
Reference in new issue