From 08635302b6441f37a589d50dada507d0c329315c Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 30 Jan 2026 16:59:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=B0=83=E7=94=A8=E4=BC=98=E5=8C=96=E5=99=A8=E4=B8=AD?= =?UTF-8?q?=E7=9A=84function=5Fexists=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除CompilerBase.php中多余的空行 - 重构FuncCallOptimizer.php中的function_exists逻辑,支持字符串字面量的大小写转换和转义处理 - 在function_exists调用中添加严格模式参数支持 - 更新micro_bench.php中的代码格式和测试执行逻辑 - 激活之前被注释掉的性能测试用例 --- examples/micro_bench.php | 19 ++++++++++--------- src/Php/CompilerBase.php | 1 - src/Php/FuncCallOptimizer.php | 8 +++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/micro_bench.php b/examples/micro_bench.php index b20d0d53..a35288d7 100644 --- a/examples/micro_bench.php +++ b/examples/micro_bench.php @@ -16,9 +16,10 @@ function simpleudcall($n) { function hallo2() { } -function simpleicall($n) { - for ($i = 0; $i < $n; $i++) - $ret = function_exists('hallo'); +function simpleicall($n) +{ + for ($i = 0; $i < $n; $i++) + $ret = function_exists('hallo'); } class Foo { @@ -287,14 +288,14 @@ function main() empty_loop(N); $t = end_test($t, 'empty_loop'); $overhead = $last_time; -// simpleucall(N); -// $t = end_test($t, 'func()', $overhead); -// simpleudcall(N); -// $t = end_test($t, 'undef_func()', $overhead); + simpleucall(N); + $t = end_test($t, 'func()', $overhead); + simpleudcall(N); + $t = end_test($t, 'undef_func()', $overhead); simpleicall(N); $t = end_test($t, 'int_func()', $overhead); -// Foo::read_static(N); -// $t = end_test($t, '$x = self::$x', $overhead); + Foo::read_static(N); + $t = end_test($t, '$x = self::$x', $overhead); // Foo::write_static(N); // $t = end_test($t, 'self::$x = 0', $overhead); // Foo::isset_static(N); diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index d17b0ced..4c386efa 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -763,7 +763,6 @@ class CompilerBase extends \PhpAot\Core\Translator if (!$this->isVarExpr($expr->var)) { $this->fatalError($expr, 'When an assignment expression serves as an rvalue, it must be an assignment of a variable'); } - return $this->parseExpr($expr); default: return $this->parseExpr($expr); diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index f1f95807..68276547 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -45,7 +45,13 @@ trait FuncCallOptimizer return 'php::math::abs(' . $this->parseIdentifier($expr->args[0]->value) . ')'; } if ($name === 'function_exists') { - return 'php::fn::function_exists(' . $this->parseIdentifier($expr->args[0]->value) . ')'; + $funcName = $expr->args[0]->value; + if ($this->isScalarString($funcName)) { + $funcName = $this->getLiteralString(strtolower(trim($funcName->value, '\\'))); + return 'php::fn::function_exists(' . $funcName . ', true)'; + } else { + return 'php::fn::function_exists(' . $this->parseIdentifier($funcName) . ')'; + } } return false;