If we are stuck on PHP 5.0 for some reason, we can use the __autoload()
function in place of the SPL autoloader registry. There are drawbacks to doing things this way, but under PHP 5.0 it is our only alternative. We do not need to register it with SPL (in fact, we cannot, since SPL was not introduced until PHP 5.1). We will not be able to mix-and-match other autoloaders in this implementation; only one __autoload()
function is allowed. If an __autoload()
function is already defined, we will need to merge this code with any code already existing in the function:
setup.php
1 <?php
2 // ... setup code ...
3
4 // define an __autoload() function
5 function __autoload($class)
6 {
7 // ... the global function code ...
8 }
9
10 // ... other setup code ...
11 ?>
I strongly recommend against using this kind of implementation in PHP 5.1 and later.