From c4b7e3022abadbe80a7d7beaa77ad1aabf810c25 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 28 Apr 2026 14:33:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0use=E8=AF=AD=E5=8F=A5=E8=A7=A3=E6=9E=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正useFunctions映射返回值,确保函数名正确拼接 - 修复use语句类型判断逻辑,处理未知类型情况 - 添加any函数polyfill支持 - 新增函数use测试用例验证功能正确性 --- examples/error/undef-var.php | 5 +++++ src/Php/CompilerBase.php | 5 +++-- src/polyfills.php | 5 +++++ tests/aot/namespace/use-func.phpt | 20 ++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 examples/error/undef-var.php create mode 100644 tests/aot/namespace/use-func.phpt diff --git a/examples/error/undef-var.php b/examples/error/undef-var.php new file mode 100644 index 00000000..89a4c731 --- /dev/null +++ b/examples/error/undef-var.php @@ -0,0 +1,5 @@ +useFunctions[$funcName])) { - return $this->useFunctions[$funcName]; + return $this->useFunctions[$funcName] . '\\' . $funcName; } return $funcName; } @@ -4679,7 +4679,8 @@ class CompilerBase extends \PhpAot\Core\Translator $code = ''; foreach ($v2->uses as $use) { $id = $this->parseIdentifier($use->name); - if ($use->type === Node\Stmt\Use_::TYPE_FUNCTION) { + $type = $use->type !== Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $v2->type; + if ($type === Node\Stmt\Use_::TYPE_FUNCTION) { $lastIndex = strrpos($id, '\\'); $fn = substr($id, $lastIndex + 1); $ns = substr($id, 0, $lastIndex); diff --git a/src/polyfills.php b/src/polyfills.php index b6bc0556..5b72e83b 100644 --- a/src/polyfills.php +++ b/src/polyfills.php @@ -43,3 +43,8 @@ function &refval(&$var) { return $var; } + +function any(mixed $var): mixed +{ + return $var; +} \ No newline at end of file diff --git a/tests/aot/namespace/use-func.phpt b/tests/aot/namespace/use-func.phpt new file mode 100644 index 00000000..0bd2d322 --- /dev/null +++ b/tests/aot/namespace/use-func.phpt @@ -0,0 +1,20 @@ +--TEST-- +use function +--FILE-- + +--EXPECT-- +string(11) "App\Foo\bar" \ No newline at end of file