spl_autoload_register意外T_FUNCTION

时间:2012-06-16 10:58:15

标签: php api

  

可能重复:
  unexpected T_FUNCTION with php 5.2.17 but fine on localhost and php 5.3.10

我不习惯用PHP编程,这是我第一次使用API​​,所以这就是我调用它的方式(从他们的wiki中复制/粘贴)

spl_autoload_register(function($class) {
    $dir = __DIR__ .'/lib/';
    $file = $dir . strtr($class, '\\', '/') . '.php';
    if (file_exists($file)) {
        require $file;
        return true;
    }
});

use WowApi\Client;

当我在自己的计算机上使用localhost时,一切正常,我没有任何警告,没有错误,它工作正常。问题是当我在我的FTP上传这个时,我遇到了以下错误:

Parse error: syntax error, unexpected T_FUNCTION, expecting ')'

这是指这一行:

spl_autoload_register(function($class) {

我被告知要在我的.htaccess中写这个:

suPHP_ConfigPath /home/MYUSERNAME/public_html/php.ini

这在我的php.ini

safe_mode = OFF

但不幸的是没有任何作用,我仍然有错误。你们对如何解决这个问题有所了解吗?提前谢谢!

1 个答案:

答案 0 :(得分:4)

匿名函数来自php 5.3,检查服务器的php版本。如果低于5.3,则需要先定义函数。