Re: [PHP3] Re: [PHP4BETA] Re: [PHP3] OO
| From: | Zeev Suraski | Date: | Thu, 05 Aug 1999 05:19:55 +0000 |
| Subject: | Re: [PHP3] Re: [PHP4BETA] Re: [PHP3] OO | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3132@lists.php.net to get a copy of this message | ||
At 01:32 05/08/99 , Manuel Lemos wrote:
There is no mention in the documentation about being able to register more than one shut down function. Does that work like that in PHP 3 too?Yes, it always has.
I believe that just like you don't have copy constructors and programmers don't assume that the constructor method is called on copy, you could have a destructor method that would be called eventually more than once for the same instance if that is the case and the programmers should be aware that it may happen.I happen to like operator overloading and OO programming a lot, I just don't think it fits into PHP. The main difference is that it's very easy to say when constructors are called - they're called when you use the 'new' operator, exactly and only then. Defining when destructors are called, or copy constructors - that's almost impossible.
For instance, a destructor could close a file geting the identifier from a instance variable and would set to 0 to prevent closing it again: class some_class {Not really. The problem doesn't occur when you have multiple variables pointing at the same zval (pval) value - in that case, we can easily rely on Zend's reference counting to call the destructor only when the last reference is deleted. The problem occurs when there are actually multiple zval's that contain the data of the same object (they contain the class type and the properties - but changing one will not change the other, and, they don't have their resources doubled - they point at the same resources (e.g. file handles)).$file=0;Function Destructor() { if($this->file) { fclose($this->file); $this->file=0; } }...}
Great. BTW, couldn't you add a similar support to XML call functions. You could have something like xml_set_handler_object($parser,$object) and then instead of calling global functions the handlers would call the object methods.No idea what xml_set_handler_object() is, but I assume that once I demonstrate how to do it with register_shutdown_function(), people will easily follow with other examples. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il