From 2050945532aa87a7e0b436064908c045a0af4307 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 31 Mar 2026 15:51:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E8=AD=A6?= =?UTF-8?q?=E5=91=8A=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E7=94=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CompilerBase 中添加 warning 方法用于显示警告信息 - 添加 warningUndefinedBehavior 方法处理潜在的行为不一致警告 - 在 FuncCallOptimizer 中对 func_get_args、func_get_arg 和 func_num_args 调用添加警告提示 - 确保动态执行行为的一致性检查 --- src/Php/CompilerBase.php | 10 ++++++++++ src/Php/FuncCallOptimizer.php | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 90cd516b..0fbae6a9 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2185,11 +2185,21 @@ class CompilerBase extends \PhpAot\Core\Translator $this->error("{$msg} in {$this->file}:{$node->getStartLine()}"); } + protected function warning(Node $node, string $msg): void + { + $this->climate->yellow("{$msg} in {$this->file}:{$node->getStartLine()}"); + } + protected function errorUndefinedVariable(Variable $node): never { $this->fatalError($node, "The variable `\${$node->name}` is undefined"); } + protected function warningUndefinedBehavior(NodeAbstract $expr): void + { + $this->warning($expr, 'Use this expression carefully, which may be inconsistent with the dynamic execution behavior'); + } + protected function dump(NodeAbstract $v): void { if ($this->debugLine == $v->getStartLine()) { diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index 216069b5..926dd2d5 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -14,6 +14,7 @@ trait FuncCallOptimizer { public function genFuncGetArgs(string $name, Node\Expr\FuncCall $expr): string { + $this->warningUndefinedBehavior($expr); $funcDef = $this->functionDef; $list = []; foreach ($funcDef->argInfoList as $i => $argInfo) { @@ -30,6 +31,7 @@ trait FuncCallOptimizer public function genFuncGetArg(string $name, Node\Expr\FuncCall $expr) { + $this->warningUndefinedBehavior($expr); $position = $expr->args[0]->value; if ($this->isScalarInt($position)) { $funcDef = $this->functionDef; @@ -109,6 +111,7 @@ trait FuncCallOptimizer protected function genFuncNumArgs(string $name, Node\Expr\FuncCall $expr): string { + $this->warningUndefinedBehavior($expr); $funcDef = $this->functionDef; foreach ($funcDef->argInfoList as $i => $argInfo) { if ($argInfo->variadic) {