I am working on replacing some old objects with updated ones in php. The site currently has an __autoload function that simply calls a .inc file in the include directory. I have created a new autoload function for the updated objects using spl_autoload_register. It uses a directory named lib and namespaces.
I have an object named Sample, and the old object, also named Sample, references a definition in include/sample.inc. Then new object path is lib/Sample.php. My problem is, even though I am using the spl_autoload_register on the page that is calling the object, it is still calling the old object. Here is my code (please note that the __autoload() is defined prior to reaching this page).
<?php
spl_autoload_register('autoload_lib');
$sample_id = req('sample_id');
$alert = req('alert');
if (!empty($sample_id))
{
$sample = new Sample($sample_id);
var_dump($sample); die();
$referral = $sample->Referral();
matry::open (get_defined_vars());
}
else
{
matry::open(get_defined_vars());
}
When you start using spl_… methods, they usurp any existing __autoload function:
One can see this in a simple example:
The above example outputs “spl_autoload”
Are you sure no other autoloader has been registered at that stage in the script? You could test this by adding the prepend argument (e.g., spl_autoload_register(‘autoload_lib’, true, true); Is autoload_lib callable at that time in the script (has it’s source been included?)