Re: [PHP4BETA] Session: objects containing objects
| From: | Ulf Wendel | Date: | Thu, 24 Feb 2000 10:46:51 +0000 |
| Subject: | Re: [PHP4BETA] Session: objects containing objects | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-10814@lists.php.net to get a copy of this message | ||
thies@digicol.de wrote:
>
> On Thu, Feb 24, 2000 at 09:18:56AM +0000, Ulf Wendel wrote:
> > Pease don't tell me the OO features of PHP are limited by design. Is it
> > really that difficult to implement the for the purpose of serialization
> > most important function getFields()? By the way Java is able to
> > serialize object containing objects...
>
> ulf - this is not a language question but a question
> regarding the serializer/unserializer used by the
> session-module. currently we support the builtin serialize()
> and wddx modules.
Hmmh, now I'm confused. Am I not requesting a new language feature when
I'm talking about new functions for introspection, such as getFields()
although my example is pretty close to an feature request for the
serializer?
I still don't know how the PHP4 serializer will handle an object
containing other objects.
> i would like to add the needed functionality to PHP 4 so that
> phplib can be used with "native" session support.
>
> as i've never used phplib myself could you please send me
> some tiny sample files that show the extra features of
> phplib's serializer opposed to PHP 4's?
I don't know the differences in detail, because I don't know the
features of the php4 serializer, that's why I'm asking...
PHPLIB works on $GLOBALS, generates code that can be executed by eval()
and stores it in a session container. This works pretty well on:
- plain variables
- arrays
It's limited when it comes to objects. PHP3 does not provide any
function for introspection. To make an object clonable/serializable the
phplib user must provide some information about the object:
- an object must provide it's classname in the slot string $classname
- an object must provide it's slots to be serialized in the slot array
$persistent_slots
Brief example:
class foo {
var $classname = "foo";
var $persistent_slots = array ( "slot1", "slot2" );
var $slot1 = "value1";
var $slot2 = "value2";
}
phplib does not handle objects in objects. phplib calls always the
"default constructor" which leads to further limitations. These could be
avoided if the phplib cares on another slot $constructor_call = array
("type" => "value") created by the constructor of a class.
To be able to write your own serialize with php you would need:
getFields( Object $obj );
getFielType ( Slot $slot );
getConstructorCall ( Object $obj );
- BUT - I'm not in favour to do so if the php4 serialize works perfect
on objects. The major difference between the phplib serialize and the
php4 serialize seems to be that php4 serializes all slots. phplib does
not.
I personally prefer the php4 way, don't know what Kris does. I'll ask
him later this day. In my eyes the number of slots in an object that do
not contain scratch data are far bigger than the number of slots
containing temporarily data that blows up the amount of serialized data.
So I'd like to mention the slots not to be serialized not the slots to
be serialized ( var $non_persistent_slots = array() instead of var
$persistent_slots = array(). Nevertheless phplib has to do serialize the
way it does, because of missing features for object introspection.
To make it short: I'd replace the phplib serialize with the php4
serialize.
As beeing a student of political sience not computer sience I can't
think of situation where it's necessary to clone an object partly. But I
would like to see some basic introspection function at least for
debugging. Is a warrantied that an object will ever be an array you can
look at?
Ulf