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

From: Date: Fri, 25 Feb 2000 15:27:31 +0000
Subject: Re: [PHP4BETA] Re: SESS: objects containing objects *final statement*(?) please read!
References: 1 2 3  Groups: php.version4 
Request: Send a blank email to php-version4+get-10953@lists.php.net to get a copy of this message
On Fri, 25 Feb 2000, Stig Bakken wrote: > 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. That's fine. > As long as the values are references, I don't see any harm in including > them. I'd say they should just increment the refcount and return the value, not use the actual reference (it'd be bad if you changed the value and the class var value would also change). > 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); > } > } > } Would register_object_serialize_method() use some global table where it registers class name and these methods? -Andrei "The time from now until the completion of the project tends to become constant." -- Douglas Hartree

« previous php.version4 (#10953) next »