ho derick... 

could you read over this mail, i plan to send to php-dev-ml.
i'm not sure if i used the correct words.. you know.. my english :))
thanx...

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

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.

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to