RE: [PHP-DEV] serializing references, almost without modifications

From: Date: Wed, 19 Jul 2000 14:38:02 +0000
Subject: RE: [PHP-DEV] serializing references, almost without modifications
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-25117@lists.php.net to get a copy of this message
Hi, Using __sleep() and __wakeup() I can have the pleasure of recreating all the references by making new objects, and that is not really an (imho) interesting way to do it. Let's say I would have class x{ var $i; function y($int) { $this->i = $int; } } class z{ var $x; function q(&$x) { $this->x = &$x; } } class a{ var $x; function b(&$x) { $this->x = &$x; } } $x = new x(2); $a = new a($x); $z = new z($x); now if I have to use __wakeup and __sleep I'd have to know exactly what references are kept where in this object, by giving __sleep a logic so that it could figure out what to have fun with. With the above sample I would have to create either an array of referenced objects that I could fetch the reference from, or do some other nifty trick so that the two classes would have the same reference. Now if we have 100 class a's that quickly becomes double-work in the sense that instead of re-initiating its previous state (as the serializer should be doing had it been working with references) I have to recreate the entire reference "tree". I have an objUnit that contains objDimension and general Unit information, now the Dimension is a reference in objUnit so that if needed we can change objDimension and itll be reflected on the entire objUnits. These objUnits are stored within an objQuantity along with a float -- again as reference. These objQuantity are then in turn stored as reference in an objArticle, so that if I need a price I can calculate it based on an objQuantity since it include an objUnit. This may seem as an akward way of doing business, but in the context we're using it, it works like a charm -- except that instead of making all the objDimension/Units and Articles once and keeping them in the session we have to make them each time we hit a page. If I would have to recreate objQuantity in one of the objArticles I would have to get its float, and then recreate it from scratch by fetching the objUnit from an array -- not very elegant. I can see __sleep() and __wakeup() working perfectly for filehandles, database connections and other stuff like that. But when you have a large amount of references that you'd like to use throught a users session, it quickly becomes a cumbersome way to deal with references, unless I have completely missed the point. Kind regards, David Hjortsoe.

« previous php.dev (#25117) next »