helper.php : Required at the top of index.php
function __autoload($className) {
$path = ROOT_DIR.'/class/'.strtolower(trim($className)).'.class.php';
if (file_exists($path)) {
require_once($path);
}
}
function load_libs($class_variable_name) {
global $session;
global $_libs;
$_libs[$class_variable_name] = new $class_variable_name($session);
return $_libs[$class_variable_name];
}
From index.php I create an instance of a class :
new some_class_one();
No problem, it loads class file via __autoload.
But, in case that I call :
load_libs('some_class_two');
I getting error : Fatal error: Class 'some_class_two' not found in C:\wamp\www\helper.php on line
Any idea what to do ?
I just tested this on my machine and it works perfectly. I could not replicate the issue. This is the version of PHP I'm running:
$ php -v
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
I would suggest that you remove the .class
from your filenames. It's better to use namespaces and have the namespace/class name match the filesystem. Other than that, either your ROOT_DIR
is incorrect or your file is located in the wrong place.