From 11828d3b5aa8e754cc51fe3e16171a5666faee63 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 26 Jan 2026 18:30:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(compiler):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=20any=20=E5=87=BD=E6=95=B0=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编译器中实现 any 函数的解析和处理逻辑 - 添加对 var 类型常量的支持 - 扩展测试用例以验证 any 函数的功能 --- src/Php/CompilerBase.php | 6 ++++++ src/Php/Constants.php | 1 + tests/aot/any.phpt | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/aot/any.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index f3da5c1f..2e8b6334 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -866,6 +866,12 @@ class CompilerBase extends \PhpAot\Core\Translator if (count($right->args) === 2 and $fn === 'objval' and $this->isScalarString($right->args[1]->value)) { $this->objects[$var] = $this->parseIdentifier($right->args[1]->value); $type = self::TYPE_OBJECT; + } elseif (count($right->args) === 1 and $fn === 'any') { + $type = self::TYPE_VAR; + if (!$this->hasVar($var)) { + $this->addLocalVar($var, $type); + } + return $var . ' = ' . $this->parseIdentifier($right->args[0]->value); } } diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 1a556308..d3e0dd88 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -34,6 +34,7 @@ class Constants 'int', 'new', 'null', + 'var', 'or', 'and', 'private', diff --git a/tests/aot/any.phpt b/tests/aot/any.phpt new file mode 100644 index 00000000..76815d40 --- /dev/null +++ b/tests/aot/any.phpt @@ -0,0 +1,13 @@ +--TEST-- +any +--FILE-- + +--EXPECT-- +float(2.5)