diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 87c607f9..724a1e52 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -349,6 +349,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected CLImate $climate; protected bool $stubFile = false; protected bool $enableProfiler = false; + protected bool $noProgress = false; protected bool $forTest = false; protected Parser $parser; protected PrettyPrinter $printer; @@ -4699,7 +4700,9 @@ class CompilerBase extends \PhpAot\Core\Translator $funcName = ''; } - if ($class and $funcName and !$magicMethod) { + $methodIsAbstract = $class && $funcName && $this->hasClass($class) + && ($this->getMethodFlags($class, $funcName) & Modifiers::ABSTRACT); + if ($class and $funcName and !$magicMethod and !$methodIsAbstract) { $methodPtr = $this->getMethodPtr($class, $funcName); } else { $methodPtr = $method; @@ -5530,6 +5533,13 @@ class CompilerBase extends \PhpAot\Core\Translator } } if ($nativeFunc) { + if ($this->hasClass($class) && $this->getMethodFlags($class, $method) & Modifiers::ABSTRACT) { + return false; + } + if ($object !== 'this_' && !isset($this->context->stableObjects[$object]) + && ($this->isAbstractClass($class) || $this->isInterface($class))) { + return false; + } $this->checkFunction($nativeFunc); if ($this->hasFunction($nativeFunc)) { return $nativeFunc; diff --git a/tests/aot/dynamic_call/call-abstract-method.phpt b/tests/aot/dynamic_call/call-abstract-method.phpt new file mode 100644 index 00000000..266ab369 --- /dev/null +++ b/tests/aot/dynamic_call/call-abstract-method.phpt @@ -0,0 +1,42 @@ +--TEST-- +call abstract base method through concrete object +--FILE-- + 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