Re: [PHP4BETA] Re: SESS: objects containing objects *final statement*(?) please read!

From: Date: Fri, 25 Feb 2000 15:22:35 +0000
Subject: Re: [PHP4BETA] Re: SESS: objects containing objects *final statement*(?) please read!
References: 1 2  Groups: php.version4 
Request: Send a blank email to php-version4+get-10951@lists.php.net to get a copy of this message
Andrei Zmievski wrote: > > On Fri, 25 Feb 2000, Boris Erdmann wrote: > > This would be the ability to traverse the slots of a class. IHMO > > Yes it would be nice to have *three* functions: > > > > - class_member_vars("classname") > > which implies class_member_vars(get_class($obj)) (the original > > question from Andrei) > > I think it should be get_class_vars($obj), not > get_class_vars("classname"). We want to get all the object member vars > _at the time of the call_, not the default member vars when the class > was declared. Although we can do it both ways: > > get_class_vars(string classname) - gets default class vars > get_class_vars(object $obj) - gets the current class vars It would be more clear to have two functions: get_class_vars() and get_object_vars(), to make sure people don't mix up classes and their instances. > And what should it return - just the var names, or also values? As long as the values are references, I don't see any harm in including them. > > - class_methods("classname") > > Might be useful. Useful, and it should definitely be there for completeness. > > - get_superclass("classname") > > That's called get_parent_class(). Now, when it comes to waking up unserialized objects again, calling the constructor is definitely not what we want. If the constructor initializes member variables, which they often do, it is plain wrong. There should probably be a method called before serialization and one after unserialization. There are three ways of doing this: fixed method names like "beforeSerialize" and "afterUnserialize", method names based on the class name like "MyClass_beforeSerialize" and "MyClass_afterUnserialize", or having functions to register which method in your class should be used. Example: class MyDBClass { var $dbh; function MyClass($dsn) { register_object_serialize_method($this, "prepareForSerialize"); register_object_unserialize_method($this, "wakeupAfterUnserialize"); $this->dbh = DB::connect($dsn); } function prepareForSerialize() { if ($this->dbh) { $this->dbh_info = $dbh->getDSN(); $dbh->disconnect(); } } function wakeupAfterUnserialize() { if ($this->dbh_info) { $this->dbh = DB::connect($this->dbh_info); unset($this->dbh_info); } } } - Stig

« previous php.version4 (#10951) next »