From 2da2bc094f9d570403fa8e37967ea474b7e85f85 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 5 Jun 2026 19:55:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E4=B8=80=E7=AD=89=E5=8F=AF=E8=B0=83=E7=94=A8=E8=AF=AD=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编译器中实现 foo(...) 语法的占位符处理逻辑 - 添加对函数调用占位符的识别和生成支持 - 新增 first-class callable 语法的测试用例 - 实现可调用性检查的正确处理机制 --- src/Php/CompilerBase.php | 4 ++ tests/aot/callable/first-class-callable.phpt | 39 ++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/aot/callable/first-class-callable.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 9f3b43a6..b6c0ec53 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2781,6 +2781,10 @@ class CompilerBase extends \PhpAot\Core\Translator $nativeFn = $this->findNativeFunction($name); if ($nativeFn) { $expr->setAttribute('nativeCall', $nativeFn); + // 函数调用占位符,不是真实的函数调用 + if (count($expr->args) === 1 and $this->isPlaceholderExpr($expr->args[0])) { + return $this->genPlaceHolder($this->identifierToStr($expr->name)); + } $this->checkNativeCallArgs($expr, $this->getFunction($nativeFn), $expr->args, $name); try { return self::PREFIX . $nativeFn . '(' . $this->parseNativeCallArgs($expr->args, $nativeFn) . ')'; diff --git a/tests/aot/callable/first-class-callable.phpt b/tests/aot/callable/first-class-callable.phpt new file mode 100644 index 00000000..6eb1ace4 --- /dev/null +++ b/tests/aot/callable/first-class-callable.phpt @@ -0,0 +1,39 @@ +--TEST-- +First-class callable syntax foo(...) +--FILE-- +add(...); + echo $add(10, 5) . "\n"; + + $sub = Calculator::sub(...); + echo $sub(10, 3) . "\n"; + + var_dump(is_callable('multiply')); + var_dump(is_callable('nonexistent')); +} +?> +--EXPECT-- +42 +15 +7 +bool(true) +bool(false)