From c79573a9fea9a810f8914da9f28f3ea2d953710f Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 9 May 2026 19:21:12 +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 的路径处理逻辑 - 更新测试输出预期结果以匹配新的行为 --- examples/const_expr.php | 22 ++++++++++++++++++++++ src/Php/CompilerBase.php | 19 +++++++++++++++++-- src/Php/Reflection.php | 13 ------------- src/gen_stub.php | 6 +++--- 4 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 examples/const_expr.php diff --git a/examples/const_expr.php b/examples/const_expr.php new file mode 100644 index 00000000..9c7a960b --- /dev/null +++ b/examples/const_expr.php @@ -0,0 +1,22 @@ +isPassedByReference(); + } + protected function parseCallArgs(array $args, string $funcName = '', string $className = ''): string { $list_args = []; @@ -3028,7 +3043,7 @@ class CompilerBase extends \PhpAot\Core\Translator if ($arg->name !== null) { return $this->parseNamedCallArgs($args, $i, $list_args); } - $byRef = $funcName && Reflection::isReferenceArg($funcName, $className, $i); + $byRef = $funcName && $this->isReferenceArgument($funcName, $className, $i); if ($this->isVarExpr($arg->value)) { $name = $this->parseIdentifier($arg->value); if ($byRef) { @@ -4596,7 +4611,7 @@ class CompilerBase extends \PhpAot\Core\Translator } try { // 类名为空,这是一个 var ,类型是 any ,编译期无法获得它的类型,需要动态调用 - $class = empty($class) ? '__DYNAMIC-CALLED-CLASS__' : $class; + $class = empty($class) ? self::DYNAMIC_CALLED_CLASS : $class; return $object . '.call(' . $methodPtr . ', ' . $this->parseCallArgs($expr->args, $funcName, $class) . ')'; } catch (PlaceHolder) { return $this->genPlaceHolder($this->genArray([$object, $method])); diff --git a/src/Php/Reflection.php b/src/Php/Reflection.php index 863232d1..6756a3a9 100644 --- a/src/Php/Reflection.php +++ b/src/Php/Reflection.php @@ -153,19 +153,6 @@ class Reflection return $args[$index]; } - public static function isReferenceArg(string $fnName, string $className, int $index): ?string - { - if ($className) { - $param = self::getClassMethodParameter($className, $fnName, $index); - } else { - $param = self::getFunctionParameter($fnName, $index); - } - if (!$param) { - return null; - } - return $param->isPassedByReference() ? $param->getName() : null; - } - public static function hasMethod(string $extends, string $method): bool { $class = self::getClass($extends); diff --git a/src/gen_stub.php b/src/gen_stub.php index 4eb70b78..bf18b7aa 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -2324,13 +2324,14 @@ class EvaluatedValue } } - foreach ($allConstInfos as $const) { - if ($constName != $const->cValue) { + foreach ($allConstInfos as $name => $const) { + if ($constName != $name) { continue; } $constType = ($const->phpDocType ?? $const->type)->tryToSimpleType(); if ($constType) { + // 这里返回的并不是真正的值,而是一个类型的占位符,最终的运算由编译器完成,此处仅用于 ArgInfo 处理 if ($constType->isBool()) { return true; } elseif ($constType->isInt()) { @@ -2338,7 +2339,6 @@ class EvaluatedValue } elseif ($constType->isFloat()) { return M_PI; } elseif ($constType->isString()) { - var_dump($const); return $const->name; } elseif ($constType->isArray()) { return [];