Rápli András
Rápli András

Reputation: 3923

PHP autoloading fails on other server

I've made a website module on localhost, and am trying to get it work on the live server, which is frustrating, as I'm sure that every class to be loaded has right syntax. They don't get loaded even though the path is the same.

function __autoload($class_name) {
   require("adk3/classes/".$class_name.".php");
}

The above was the original which worked on localhost executed from the root folder (htdocs/index.php)

function autoloader(){
       require("adk3/classes/".$class_name.".php");
}
spl_autoload_register('autoloader',true);

And this is which I was also trying and also didn't work. I've also checked absolute paths:

require(dirname(__FILE__)."/adk3/classes/".$class_name.".php");

The script stops execution at $userList = new UserList(); without any error message even with E_ALL turned on. With the dirname syntax file_exists() says yes - they exist.

Edit (additional info):

Upvotes: 0

Views: 129

Answers (1)

Rápli András
Rápli András

Reputation: 3923

Took me ages to figure it out:

The files have been required successfully, that's why I never got any error message. The classes written in the required files were okay according to PHP5.4+. Since I had PHP 5.3 running on the new server, it couldn't interpret the new shorthand array syntax [], which I used in some methods.

Upvotes: 1

Related Questions