dongwu8064 2014-07-15 06:28
浏览 32
已采纳

如何解决此错误,以便我可以继续为我的网站制作注册和登录系统?

I know that php is getting very old but it is the only coding that i partially know that is easy enough to use for a registration and login system. If more coding or information is needed then please ask before marking as a non-question.

I keep receiving the error below. My init.php and config.php are included. mysql info has been changed for the protection of my website.

Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/a5236314/public_html/ooplr/core/init.php on line 20

init.php

<?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'
)
);

spl_autoload_register(function($class){  // 'This is line 20'
require_once 'classes/' . $class . '.php';
});

require_once 'functions/sanitize.php';

config.php

<?php
class Config{
public static function get($path = null) {
    if($path) {
        $config = $GLOBALS['config'];
        $path = explode('/', $path);

        print_r($path);
    }
}
}
  • 写回答

1条回答 默认 最新

  • dongzu0742 2014-07-15 06:42
    关注

    In PHP versions older than 5.3, anonymous functions are seen as syntax errors. To pass a callback function, do this:

    function callback($class){  
        require_once 'classes/' . $class . '.php';
    }
    spl_autoload_register('callback');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?