Re: [PHP4BETA] Session: objects containing objects

From: Date: Thu, 24 Feb 2000 16:43:06 +0000
Subject: Re: [PHP4BETA] Session: objects containing objects
References: 1 2 3 4 5  Groups: php.version4 
Request: Send a blank email to php-version4+get-10877@lists.php.net to get a copy of this message
Ulf Wendel wrote: > > Boris, do you have any experiences with constructors and > sessions? PHPLIB can't handle the following code, how about php4? > > <?php > class foo() { > var $mode; > function foo( $mode ) { > $this->mode = $mode; > } > } > $sess->register("foo"); > ?> Hmm, i dont semm to get your point on this: do you want to sess->register a *class* (see the code!)? that wont work with PHPLIB and php4 either. I assume you want to: ---------------------- class foo() { var $mode; function foo( $mode ) { $this->mode = $mode; } } $obj = new foo("mode"); $sess->register("obj"); ----------------------- > PHPLIB would need a new slot $constructor_param() = array() that > gets filled by the constructor of foo to be able to serialize the > object. Or I get yet another function: get_constructor() ... Ok. I dont know if this is a generic case, but i think this currently dont work in php4. but you can work around that by: ------------------------ class foo() { var init_mode; # maybe you want an init array var $mode; function foo( $mode="" ) { if ( ( "" != $mode ) && isset( init_mode ) ) { #assuming the obj gets unserialized $this->mode = $init_mode; } else { #assuming this is an original instance $this->mode = $mode; $this->init_mode = $mode; } } } ------------------------- Now the original constructing call variable is stored - and restored when unserialized. I think that this is the only sensible way to do so, because normally you wouldnt want to change back $obj->mode to the original instantiation value because that would make serialization senseless. In my opinion your special case needs a solution like this, maybe an array and a loop instead of the above. Generally, thats what constructor functions are for: calculating specialized instantiations. Boris

« previous php.version4 (#10877) next »