refactor(php): 优化编译器方法调用逻辑

- 简化方法指针获取条件判断
- 使用内部类检查替代抽象方法和重写方法检查
- 移除不必要的方法标志位检测
- 重构动态调用测试用例
pull/3/head
韩天峰 2 months ago
parent 23f1a1eef9
commit 7eeb416f6a
  1. 7
      src/Php/CompilerBase.php
  2. 33
      tests/aot/dynamic_call/return-base-object.phpt

@ -4700,12 +4700,7 @@ class CompilerBase extends \PhpAot\Core\Translator
$funcName = '';
}
$methodIsAbstract = $class && $funcName && $this->hasClass($class)
&& ($this->getMethodFlags($class, $funcName) & Modifiers::ABSTRACT);
$methodIsOverridden = $class && $funcName && $this->isOverrideMethod(
$this->getOverrideMethodName($class, $funcName)
);
if ($class and $funcName and !$magicMethod and !$methodIsAbstract and !$methodIsOverridden) {
if ($class && $funcName && !$magicMethod && $this->isInternalClass($class)) {
$methodPtr = $this->getMethodPtr($class, $funcName);
} else {
$methodPtr = $method;

@ -0,0 +1,33 @@
--TEST--
call overridden method through parent parameter type
--FILE--
<?php
class Base
{
static function create() {
return new Impl;
}
}
class Impl extends Base
{
public function run(): string
{
return 'impl';
}
}
function get_impl(): Base
{
$obj = Base::create();
return $obj;
}
function main(): int
{
$impl = get_impl();
echo "result: " . $impl->run() . "\n";
}
?>
--EXPECT--
result: impl
Loading…
Cancel
Save