I'm using spl_autoload_register
in order to load classes.
I have an index.php
file that includes an init.php
file. The spl_autoload_register
function is called in the init.php
file.
In the index.php
file, it works properly: I can create classes and stuff, their names are resolved.
But later on, in the index.php
, I include another file, work.php
to do some specific task.
Oddly, in the work.php
, the class I'm using are not found.
If I call the spl_autoload_register
once again in work.php
, the class can then be resolved.
The really odd thing about it is that this behavior is not consistent: On my test server, I don't have to duplicate the spl_autoload_register
call, but on my production server, it's compulsory.
Am I missing some options in the php.ini
?
Edit/Updated: Here is the content on the init.php
file, just in case:
<?php
function my_autoload($class){
include 'class/' . $class . '.class.php';
}
spl_autoload_register('my_autoload');
?>
And my index.php :
<?php
require_once 'include/init.php';
$barcode = new Barcode();
// here is a bunch of test and stuff
include 'work.php';
?>
And my work.php :
<?php
$myObj = new Barcode();
// more useles stuff
?>
The barcode is created flawlessly in the index.php code part, but fails in the work.php part...