RE: [PHP4BETA] A quick clarification question about PHP4...
| From: | Zeev Suraski | Date: | Wed, 01 Sep 1999 16:16:55 +0000 |
| Subject: | RE: [PHP4BETA] A quick clarification question about PHP4... | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3972@lists.php.net to get a copy of this message | ||
At 14:06 01/09/99 , Samuel Liddicott wrote:
Its a bad feature to be able to temporarily turn a static variable into a temporary variable, and NOT BE ABLE to clear the contents without doing this!Unset means 'forget about this symbol'. It never was only about that symbol's value (as in, it didn't assign it with "", but actually tried to delete any trace of it), and in PHP 4.0, its behavior is 100% clean and consistent. There's no resemblance in any way to C/C++ or any other language of the sort, since they have no notion of unsetting a symbol.
Howabout this, then, for a userland unset: function my_unset(&$x) { # any non-existant variable will do... $x=$unset; } This CAN safely be used on static variables. But can someone answer, whatever Zeev may have intended for php3 and however much the new behaviour may make his source code more poetic; who expects "un-staticize" to be a side effect of "un-set"? And seriously, when would any decent programmer actually WANT this behaviour?Hmm, I'm not sure why this sets $x as unset, but it shouldn't (and it'll most likely be fixed, so don't rely on it). Unset() has not been specifically defined for static or global variables. It has a clear and consistent definition that covers both static and global variables, and whether it's really useful or not in these specific cases doesn't really matter much.
Also, is it deliberate that unset on a pass-by-reference argument ($&) unsets the local reference and not the contents of the passed variable? Is this part of the same thing?Yes, it's a part of the same thing. You can't unset a symbol you don't have direct access to, that is, that is in your local symbol table. Always, you only have access to the symbol that is in your local symbol table, or the global symbol table through $GLOBALS[]. These symbols may be references to other symbols, but unset()ing them doesn't affect the references they're connected to. PHP 4.0 uses references in all of the above cases - in pass by reference, statics and globals. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il