From eaa1b4cd9a0c2ed8cc12b15a773a785e1073c69f Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 9 May 2026 16:41:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E5=99=A8=E5=9F=BA=E7=B1=BB=E4=B8=AD=E7=9A=84=E5=9B=9E?= =?UTF-8?q?=E6=BA=AF=E6=89=93=E5=8D=B0=E5=92=8C=E7=B1=BB=E5=9E=8B=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E9=AA=8C=E8=AF=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 printBacktraceOnError 默认值从 false 修改为 true - 扩展子类作为父类返回时的类型检查,支持抽象类或接口 - 更新 SimpleType::fromNode 和 fromString 方法以支持 ArrayType 返回类型 - 修改测试用例中 ZipArchive 的路径处理逻辑 - 更新测试输出预期结果以匹配新的行为 --- src/Php/CompilerBase.php | 8 ++++---- src/gen_stub.php | 5 +++-- tests/aot/ref-call-arg.phpt | 9 +++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 5c58c343..051a14d2 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -174,7 +174,7 @@ class CompilerBase extends \PhpAot\Core\Translator protected int $floatPrecision = 17; protected bool $debug = false; protected bool $formatCode = true; - protected bool $printBacktraceOnError = false; + protected bool $printBacktraceOnError = true; protected bool $noLiteralStrings = false; protected bool $noConsole = false; // Windows: hide console window protected string $sanitize = ''; // Sanitizer type (address, undefined, etc.) @@ -1800,9 +1800,9 @@ class CompilerBase extends \PhpAot\Core\Translator } elseif (!$this->isInheritedFrom($objectClass, $returnClass)) { $this->fatalError($v, 'The return type is `' . $returnClass . '`, cannot return an instance of `' . $objectClass . '`'); } - // 把子类当做父类返回时,父类必须是抽象类 - 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"); + // 把子类当做父类返回时,父类必须是抽象类或者接口 + if ($objectClass and $objectClass !== $returnClass and !$this->isAbstractClass($returnClass) and !$this->hasInterface($returnClass)) { + $this->fatalError($v, "When returning a subclass `$objectClass` instance as parent type, the parent class `$returnClass` must be abstract/interface"); } } diff --git a/src/gen_stub.php b/src/gen_stub.php index 4c437546..4eb70b78 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -218,7 +218,8 @@ class SimpleType { public /* readonly */ string $name; public /* readonly */ bool $isBuiltin; - public static function fromNode(Node $node): SimpleType { + public static function fromNode(Node $node): SimpleType|ArrayType + { if ($node instanceof Node\Name) { if ($node->toLowerString() === 'static') { // PHP internally considers "static" a builtin type. @@ -244,7 +245,7 @@ class SimpleType { throw new Exception("Unexpected node type"); } - public static function fromString(string $typeString): SimpleType + public static function fromString(string $typeString): SimpleType|ArrayType { switch (strtolower($typeString)) { case "void": diff --git a/tests/aot/ref-call-arg.phpt b/tests/aot/ref-call-arg.phpt index 8aa044b5..e1b7f65a 100644 --- a/tests/aot/ref-call-arg.phpt +++ b/tests/aot/ref-call-arg.phpt @@ -5,7 +5,8 @@ ref call arg function main() { $zip = new ZipArchive(); - if ($zip->open(__DIR__ . '/../../examples/test.zip') === TRUE) { + $path = realpath(__DIR__ . '/../../../data/test.zip'); + if ($zip->open($path) === TRUE) { for ($idx = 0; $s = $zip->statIndex($idx); $idx++) { $rs = $zip->getExternalAttributesIndex($idx, $opsys, $attr); var_dump($rs, $idx, $opsys, $attr); @@ -35,8 +36,12 @@ bool(true) int(2) int(3) int(2176057344) +bool(true) +int(3) +int(3) +int(2176057344) OK value foo bar baz -DONE +DONE \ No newline at end of file