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)