Question

Hello guys i am trying to use the spl autoload function it works perfectly on my local server but it returns an error when i am online. i tink its server problems but i'll need someone to steer me which way to look i have the code below

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

and the error

Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/www/ftwrkdesign.com on line 22

NB: classes is a folder and absolute path to it returned same error php server version is 5.5.29

Was it helpful?

Solution

Check if you php version supports anonymous functions , they come only from php 5.3 . If your version is below 5.3 you should define your function before passing it to spl_autoload_register() .

<?php
    function qwerty($class){
        require_once 'classes/'. $class .'.php';
    }
    spl_autoload_register('qwerty'); 

OTHER TIPS

The PHP version on your server does not allow anonymous functions.

That's why the parser doesn't allow the function keyword after the opening parenthesis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top