From b6e2741c3107154b932aca91f4cd9b5104f03a7e Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 26 Feb 2026 16:37:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(compiler):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E5=92=8C=E6=97=A0=E5=8F=98=E9=87=8F=E6=8D=95=E8=8E=B7=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在方法调用解析中添加了变量表达式检查功能 - 实现了未定义变量错误提示机制 - 更新异常捕获解析以支持无变量名的捕获语法 - 添加了临时变量名生成器来处理匿名捕获变量 - 新增 try-catch-2 测试用例验证捕获语法兼容性 --- .gitignore | 1 + src/Php/CompilerBase.php | 8 ++++++-- tests/aot/try-catch-2.phpt | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/aot/try-catch-2.phpt diff --git a/.gitignore b/.gitignore index 00a267f1..5e9baa6c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ /vendor /tmp /projects/wordpress +/projects/workerman /.php-cs-fixer.cache *.o \ No newline at end of file diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 0fcd122d..d64ac06c 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -3189,6 +3189,10 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parseMethodCall(Node\Expr\MethodCall $expr): string { + if ($this->isVarExpr($expr->var)) { + $this->errorUndefinedVariable($expr->var); + } + $object = $this->convertToObject($expr->var); if ($this->isTypedObject($object)) { $class = $this->getObjectType($object); @@ -3451,10 +3455,10 @@ class CompilerBase extends \PhpAot\Core\Translator return $code; } - protected function parseCatch(mixed $catch, string $exVar): string + protected function parseCatch(Node\Stmt\Catch_ $catch, string $exVar): string { $types = $catch->types; - $var = $this->parseIdentifier($catch->var); + $var = $catch->var ? $this->parseIdentifier($catch->var) : $this->genTmpVarName(); if (!$this->hasVar($var)) { $this->addLocalVar($var, self::TYPE_OBJECT); } diff --git a/tests/aot/try-catch-2.phpt b/tests/aot/try-catch-2.phpt new file mode 100644 index 00000000..d42365d4 --- /dev/null +++ b/tests/aot/try-catch-2.phpt @@ -0,0 +1,14 @@ +--TEST-- +try catch 2 +--FILE-- + +--EXPECT-- +Caught exception