From 76ed488b7538173b8193a488dd628d408b8396bd Mon Sep 17 00:00:00 2001 From: rango Date: Sat, 9 May 2026 16:00:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E4=BD=9C=E4=B8=BA=E7=88=B6=E7=B1=BB=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了对 objectClass 是否存在的检查,避免空值导致的错误 - 改进了错误消息,明确显示具体的子类和父类名称 - 确保只有在 objectClass 存在且不等于 returnClass 时才进行抽象类验证 --- src/Php/CompilerBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 10cc1248..5c58c343 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1801,8 +1801,8 @@ class CompilerBase extends \PhpAot\Core\Translator $this->fatalError($v, 'The return type is `' . $returnClass . '`, cannot return an instance of `' . $objectClass . '`'); } // 把子类当做父类返回时,父类必须是抽象类 - if ($objectClass !== $returnClass and !$this->isAbstractClass($returnClass)) { - $this->fatalError($v, 'When returning a subclass instance as its parent type, the parent class must be abstract'); + if ($objectClass and $objectClass !== $returnClass and !$this->isAbstractClass($returnClass)) { + $this->fatalError($v, "When returning a subclass `$objectClass` instance as parent type, the parent class `$returnClass` must be abstract"); } }