dst8922 2014-02-12 16:14
浏览 348
已采纳

解析错误:语法错误,意外T_FUNCTION,[重复]

This question already has an answer here:

what is wrong with this error i dont get it... it actualy works when i m connected to localhost but when i run it on a free domain i get this error: Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/a7812073/public_html/core/init.php on line 21 and i inserted the right info for the mysql server

<?php
session_start();

$GLOBALS ['config'] = array(
    'mysql' => array(
        'host' => '127.0.0.1',
        'username' => 'root',
        'password' => '',
        'db' => 'lr'
    ),
    'remember' => array(
        'cookie_name' => 'hash',
        'cookie_expiry' => 604800
    ),
    'session' => array(
        'session_name' => 'user',
        'token_name' => 'token'
    )
);

spl_autoload_register(function($class) {
    require_once 'classes/' . $class . '.php';

});

require_once 'functions/sanitize.php';
if(Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) {
    $hash = Cookie::get(Config::get('remember/cookie_name'));
    $hashCheck = DB::getInstance()->get('users_session', array('hash', '=', $hash));
    if($hashCheck->count()) {
        $user = new User($hashCheck->first()->user_id);
        $user->login();
    }
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • doutang3760 2014-02-12 16:19
    关注

    The problem is that you are attempting to register an anonymous function using spl_autoload_register(), but as you told that you are using PHP5.2 on your web server.

    Unfortunately PHP < 5.3 does not support anonymous functions. You need to write a "regular" function:

    function my_autoload($class) {
        require_once 'classes/' . $class . '.php';
    }
    
    spl_autoload_register('my_autoload');
    

    This will work on PHP >= 5.3 as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图