众所周知,PHP 中的函数调用会严重影响性能。这个脚本演示了这个问题:
// Plain variable assignment.
    $time = microtime(true);
    $i = 100000;
    while ($i--)
    {
        $x = 'a';
    }
    echo microtime(true) - $time."\n\n";
// 0.017973899841309
    $time = microtime(true);
    function f() { $a = "a"; return $a; }
    $i = 100000;
    while ($i--)
    {
        $x = f();
    }
    echo microtime(true) - $time."\n\n";
//0.18558096885681
顺便说一句,匿名函数是最糟糕的。你慢了 10 倍。
是否有一个 PHP-Script-Optimizer 可以减少函数调用的数量并缩小脚本?
还有这篇文章:为什么 PHP 函数调用*如此*昂贵?与本文相关