From 608db0e8c207507e0f893c7a5dfc6443f7e6262e Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 27 Apr 2026 12:01:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92=E5=92=8C=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=91=BD=E5=90=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加标量值作为引用参数时的错误检查 - 为动态调用类添加占位符处理 - 统一模块名称前缀为 app_ - 简化模块名称生成逻辑 - 添加动态调用测试用例 --- src/Php/CompilerBase.php | 5 ++++ src/Php/Translator.php | 11 +++----- tests/aot/dynamic_call/method-call.phpt | 34 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 tests/aot/dynamic_call/method-call.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 8437e1d1..2ff0d9ca 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2666,6 +2666,9 @@ class CompilerBase extends \PhpAot\Core\Translator } } else { if ($byRef) { + if ($this->isScalar($arg->value)) { + $this->fatalError($arg, 'The constants cannot be used as an argument for a reference-type parameter'); + } $list_args[] = $this->parseChainedExpr($arg->value, self::OP_REFVAL); continue; } @@ -4145,6 +4148,8 @@ class CompilerBase extends \PhpAot\Core\Translator return $object . '.call(' . $methodPtr . ')'; } try { + // 类名为空,这是一个 var ,类型是 any ,编译期无法获得它的类型,需要动态调用 + $class = empty($class) ? '__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/Translator.php b/src/Php/Translator.php index c2ae1a36..c2dc9a2d 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -46,6 +46,8 @@ class Translator extends Preprocessor protected array $defaultPropertyList = []; protected bool $useRegisterSymbolsFn = false; + protected const string MODULE_NAME_PREFIX = 'app_'; + public function __construct(string $rootPath) { parent::__construct($rootPath); @@ -584,14 +586,7 @@ CODE; public function getModuleName(): string { - if (ctype_digit($this->targetName[0])) { - return 'app_' . $this->targetName; - } - $extensions = get_loaded_extensions(); - if (in_array($this->targetName, $extensions)) { - return $this->targetName . '_'; - } - return $this->targetName; + return self::MODULE_NAME_PREFIX . $this->targetName; } public function hasObjectFileCache(string $cppFile): bool diff --git a/tests/aot/dynamic_call/method-call.phpt b/tests/aot/dynamic_call/method-call.phpt new file mode 100644 index 00000000..6f1d32ec --- /dev/null +++ b/tests/aot/dynamic_call/method-call.phpt @@ -0,0 +1,34 @@ +--TEST-- +named args +--FILE-- +end($data); + $array[] = $object; + $array[0]->end($data); +} +?> +--EXPECT-- +array(2) { + [0]=> + string(4) "ae86" + [1]=> + string(3) "bmw" +} +array(2) { + [0]=> + string(4) "ae86" + [1]=> + string(3) "bmw" +} \ No newline at end of file