As Luis Argerich points out in his article on OOP in PHP, when you serialize an object then unserialize it, you only recover the member data of the object but not the methods.
May just be me going crazy, but doesn't session handling in PHP4 serialize any session objects then unserialize them on the next session script? I think so. Doesn't this pose a major problem? In theory, but on the surface, it doesn't appear so...
Follow me on this one.
I have a stack() class - which is your standard stack and can contain variables of ANY type on it.
I also have a plan() class which is specific to my application. But, for example, one of it's data members is -
var $status;
and a few methods are -
function updatestatus();
function getstatus();
I plan to have a collection of plans which are propagated through the session on a stack...
So, I start out my application with a script which sets up the session...
session_start();
$planstack=new stack();
session_register($planstack);
$testplan=new plan();
$testplan->updatestatus("good");
$planstack->push($testplan);
now, after I've done that, within that first script, I can push and pop from the stack all I want and the member functions of the plan are accessible. Great! And... on the next script in the application....
session_start();
$workingplan=$planstack->pop();
$workingplan->updatestatus("bad");
Thats a member method, and that works!
NOW, the kicked.... each plan() object has an array of control() objects.
At this point the member variables or methods of the control() object are completely unimportant...
but lets just say that, later in the session, when I try...
session_start();
$workingplan=$planstack->pop();
$workingcontrol=$workingplan->returncontrol0();
$workingcontrol->updateinfo(); //updateinfo() being a method of control...
I get this error-
Fatal error: Call to undefined function: updateinfo() in <file> on line xx
Of course, on the $workingcontrol I can access member data DIRECTLY fine...
$temp=$workingcontrol->memberdata;
works fine.
Just the methods are lost.
Yes, it MAY be asking alot to have an object, containing an object, which contains yet another object. But, in true object oriented programming (C++) which I am used to, I can get more layers deep than that, for sure... with no problems.
Am I completely losing it? I'm not even ENTIRELY certain if this is a session problem or whatever.
And at this point, I've been on quite a long rant and I'm sure you're sick of listening, but this IS a problem.
If anyone else has encountered this problem (maybe unlikely), I dare ask, PLEASE HELP 🙂