From 0043fc78f80730f7ef4786b5f1d4635f3575f00d Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 29 May 2026 12:11:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E7=B1=BB=E5=92=8C=E6=8E=A5=E5=8F=A3=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 isNativeClass 方法用于检查是否为原生类 - 新增 isInterface 方法用于检查是否为接口 - 重构 addObject 方法中的对象验证逻辑 - 修改 TypedObject 使用条件判断逻辑 - 添加内部类测试用例 --- src/Php/CompilerBase.php | 21 ++++++++++++++------- tests/aot/class/internal-class.phpt | 12 ++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 tests/aot/class/internal-class.phpt 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