The problem I am facing is that spl_autoload($class)
passed in spl_autoload_register callback, will not load classnames which refer to the same filename, but in different directories.
What I want to achieve is using spl_autoload
, not using require
and without namespaces, to load automatically following classes:
%Project_Path%/controllers/test.php:
class TestController {
}
%Project_Path%/models/test.php:
class TestModel {
}
What I'm doing is replacing the Controller
or Model
suffix in the classname with empty string, so it will get the filename class Test
lowercased is test
, and adding the spl extension php should go to test.php
.
In the beginning of the file, I have set the include path to refer either to pear
, to current directory, to models
directory and to controllers
directory.
If there are question, what have I tried - this is what I have tried :) spl_autoload() is not recieving paths, so I have to change the include path in order to include the files.
I succeed in achieving it with require and the explicit path, then the classname, but I was in doubt if it's possible with spl_autoload
following the current pattern, without changing filename, classname or adding namespace