diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 16c28b47..05e3df33 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1825,6 +1825,16 @@ class CompilerBase extends \PhpAot\Core\Translator return Reflection::isInternalClass($name); } + protected function isNativeClass(string $name): bool + { + return $this->hasClass($name); + } + + protected function isInterface(string $name): bool + { + return $this->hasInterface($name) or $this->isInternalInterface($name); + } + protected function isAbstractClass(string $name): bool { if ($this->isInternalClass($name)) { @@ -2196,14 +2206,11 @@ class CompilerBase extends \PhpAot\Core\Translator protected function addObject(string $name, string $class): void { - // 接口、抽象类、内部类、非原生类,无法作为 TypedObject 使用 - if ($this->hasInterface($class) or - $this->isInternalClass($class) or - $this->isAbstractClass($class) or - !$this->hasClass($class)) { - return; + // 接口、抽象类、非原生类,无法作为 TypedObject 使用 + if (!$this->isInterface($class) and !$this->isAbstractClass($class) and + ($this->isNativeClass($class) or $this->isInternalClass($class))) { + $this->context->objects[$name] = $class; } - $this->context->objects[$name] = $class; } protected function hasVar(string $name): bool diff --git a/tests/aot/class/internal-class.phpt b/tests/aot/class/internal-class.phpt new file mode 100644 index 00000000..6d4bd1aa --- /dev/null +++ b/tests/aot/class/internal-class.phpt @@ -0,0 +1,12 @@ +--TEST-- +abstract class and abstract method +--FILE-- +format('Y-m-d H:i:s'); +} +?> +--EXPECTF-- +%s-%s%s %s:%s:%s \ No newline at end of file