Re: [PHP4BETA] OO Destructors
| From: | Zeev Suraski | Date: | Tue, 10 Aug 1999 20:54:28 +0000 |
| Subject: | Re: [PHP4BETA] OO Destructors | ||
| References: | 1 2 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3312@lists.php.net to get a copy of this message | ||
At 21:33 10/08/99 , George Hartz wrote:
Andi Gutmans wrote: Like Zeev mentioned the only way to make OO destructors really work is to take the Java approach where you have handlers to an object and the object holds the reference count. For example, the following two lines would result in $a being a handle to a new object of type foo, and then $b would be a reference to the same object foo. Currently in PHP 3.0 and PHP 4.0 it makes $b be an actual copy of $a. $a = new foo; $b = $a; This would also mean that when you pass an object by value to a function, it's not copied as the handler is passed which will point to the original object being passed. You'd have to copy it explicitly. Personally I prefer the handler solution which would allow us to make destructors but I have a feeling that tons of people would be bitten by such a big incompatibility with PHP 3.0 which would make it not worth it. People won't move to PHP 4.0. I might be miscalculating how many ppl this would really bite but it's kind of scary. What about a compile-time (or better yet, run-time) switch to turn on the "4.0" functionality?No. It's no 4.0 functionality since it's not implemented; It's problematic to implement it, and a rule of the thumb we've established several years ago, is that a PHP script should execute in the same way everywhere. People, the destructor issue is NOT a crucial issue. It's almost always insignificant, and when it is significant, it's always possible to take care of cleanups using register_shutdown_function() (especially with the new improvements, where you can provide it with arguments to send the shutdown function when it is called). There's no technical way to implement destructors, mainly because there's no good way to define when exactly destructors should be run, even when you describe it in English, let alone implement it in code. It's not such a big deal. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il