error with spl_autoload_register and not with __autoload

704 Views Asked by At

I am a bit confused.

I was using __autoload so far in PHP, and i am working with sessions too. Those two things worked fine together, and when i was storing some objects in sessions, the __autoload function has loaded the corresponding classes without problems.

No i was "updating" my main scripts, and wanted to change the __autoload function to the spl_autoload_register function, cause the php manual says, that __autoload could be deprecated in future.

But now, i have some problems. spl_autoload_register works fine with all classes, that i use on a "normal" way in my scripts, but when i store objects in sessions, spl_autoload_register is not able to load those classes.

When i take a look in the sessions with json_encode($_SESSION), theres something like:


    {"user":{"__PHP_Incomplete_Class_Name":"User","id":"1000","username":"foobar","email":"[email protected]"}}

With __autoload no problems ...


    {"user":{"id":"1000","username":"foobar","email":"[email protected]"}}

my functions:


    __autoload($class) {
        include 'classes/' . $class . '.php';
    }

and i tried to replace it with:


    spl_autoload_register(function($class) {
        include 'classes/' . $class . '.php';
    }

I am using PHP Version 5.3.3-7

Could somebody reproduce this error? is this maybe a bug in PHPs spl_autoload_register so far? Is __autoload so far the "better" function to use, and spl_autoload_register not able to work with sessions so far?

0

There are 0 best solutions below