faqts : Computers : Programming : Languages : PHP : Common Problems : Sessions and State

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 14 people (64%) answered Yes
Recently 3 of 7 people (43%) answered Yes

Entry

If I use session_register($object), the class is rewrite to stdClass, and no methods will be avaible. How can I solve this problem?

Jul 31st, 2000 15:54
Ben Udall, Tomas V.V.Cox,


Below is a function you can use to move all of an objects properties to 
another class.
function convert_obj($old_obj, $class_name)
{
    $obj_props = $old_obj;
    settype($obj_props, 'array');
    $new_obj = new $class_name;
    for (reset($obj_props); $key = key($obj_props); next($obj_props))
        $new_obj->$key = $obj_props[$key];
    return $new_obj;
}