feat(php): 添加警告功能并优化函数调用处理

- 在 CompilerBase 中添加 warning 方法用于显示警告信息
- 添加 warningUndefinedBehavior 方法处理潜在的行为不一致警告
- 在 FuncCallOptimizer 中对 func_get_args、func_get_arg 和 func_num_args 调用添加警告提示
- 确保动态执行行为的一致性检查
pull/1/head
韩天峰 5 months ago
parent a74e4a1226
commit 2050945532
  1. 10
      src/Php/CompilerBase.php
  2. 3
      src/Php/FuncCallOptimizer.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()) {

@ -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) {

Loading…
Cancel
Save