Re: unserialze_callback_function (description)

From: Date: Sun, 02 Dec 2001 12:26:44 +0000
Subject: Re: unserialze_callback_function (description)
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-3284@lists.php.net to get a copy of this message
show me the code! On Tue, Nov 27, 2001 at 03:12:43PM +0100, Bernd Roemer wrote: > hello... > > i'm new here on this ML. some of you might know me. > but thats not the reason for my email. I implemented a new feature, > derick kindly commited for me last night. Ok... > > if you unserialize serialized Objects, and their classes still are undefined, > you'll get an "__PHP_Incomplete_Class"-Object. To get another chance to define > the used class to instanziate the serialized Objects, you (now) can set an > unserialie_callback_function to add (include) the missing classdefinition. > Because there is an option to autostart the session, there could be no > chance to set the callback function, so i decided to use a PG() which > could be set in php.ini, .htaccess or by ini_set(), before php starts unserialize > your sessiondata. OK.. Why don't you include all classes could ever appear in your > serialized strings (or sessions)?? The reason is simple.. large projects > often contains a large number of objects.. but not (always) all of them > are needed at simultaniously. I think it saves work and time to get (for any > not yet defined classes) a callbackfunction started (with the undefined > class's name as parameter) which can define the wanted class. So you can automate > the loading of all classes really used. > > a short example: > > php.ini: > > ... > unserialize_callback_func= > ... > > test.php: > > <?php > // callback_function > function callback($classname='') { > > $classes=array('xml_tree_node'=>'Node.php','base_source'=>'libs/standard/base_source.php'); > if (file_exists($classes[$classname])) > include_once($classes[$classname]); > } > > // $r => string contains serialized Objects > > $r='O:13:"xml_tree_node":4:{s:10:"attributes";a:1:{s:4:"size";i:1;}s:8:"children";a:1:{i:0;O:13:"xml_tree_node":4:{s:10:"attributes";a:0:{}s:8:"children";a:1:{i:0;O:11:"base_source":2:{s:4:"name";s:9:"base_text";s:8:"children";s:8:"Tree.php";}}s:7:"content";s:0:"";s:4:"name";s:3:"pre";}}s:7:"content";s:0:"";s:4:"name";s:7:"bt_font";}'; > > $a=unserialize($r); > ini_set('unserialize_callback_func','callback'); > $b=unserialize($r); > > ?> > > $a then contains "__PHP_Incomplete_Class"es, but while "unserialize($b)" > the callback_function (here: callback()) will be called twice: once with > "xml_tree_node" and once with "base_source" as parameter. callback() then > includes the corresponding php-class-definitions. if 'unserialize_callback_func' > remains unset, the "__PHP_Incomplete_Class" will be returned. If a specified > callback function soesn't exist, a warning will be returned. Another warning > appears, if the specified function exists, but doesn't define the function it > was called for. > > i hope you understood description (bad english) and are agree with my > implementation. And i hope (too), you aren't angry with me because i > told derick to commit that patch before a great deal of discussion > was started. > > regards > > ---bernd roemer--- (fumanchi) > > PS.: it'll be nice if anyone could tell me what type of documentation i > should write on that new feature. > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net > For additional commands, e-mail: pear-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.pear.dev (#3284) next »