Bug #14539 Updated: Assigning null to reference has unexpected results.

From: Date: Thu, 27 Dec 2001 21:21:11 +0000
Subject: Bug #14539 Updated: Assigning null to reference has unexpected results.
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-3714@lists.php.net to get a copy of this message
ID: 14539 User updated by: jfrisby@mrjoy.com Reported By: jfrisby@mrjoy.com Status: Bogus Bug Type: PEAR related Operating System: All PHP Version: 4.0.6 New Comment: Frankly this behavior is quite unintuitive and crude. I didn't expect PHP references to behave like C pointers, but it would be nice if they behaved similarly to references in other major languages such as Java, and Perl. While the Unix filesystem analogy does clarify things, I think it's a poor model that makes objects and references clumsy to work with. If you have to explain "X will not do what you expect", you should reconsider whether or not you've chosen the optimal semantics. And another note: I would tend to think that objects (and possibly arrays) would best be assigned by reference *by default*, for both reasons of efficiency and expected semantics. Previous Comments: ------------------------------------------------------------------------ [2001-12-27 07:46:33] cox@php.net References are not C pointers. It's documented in: http://www.php.net/manual/en/language.references.php -- Tomas V.V.Cox ------------------------------------------------------------------------ [2001-12-15 20:15:14] jfrisby@mrjoy.com $foo =& new SomePEARDervidedClassWithADestructor(); $foo = null; In the above case, the destructor is never called. Presumably, the assignment is being interpreted as requesting that the object instance be nullified, rather than the more intuitive (IMNSHO) notion of nullifying the reference to the object. If you change the null-assignment line above to be: function &nullref() { return null; } $foo =& nullref(); The desired semantics are preserved. Of course, the following is presently invalid: $foo =& null; May I suggest that the above be added to allow the desired semantics in a simple fashion? Or at the very least, document this rather unexpected behavior? ------------------------------------------------------------------------ Edit this bug report at http://bugs.php.net/?id=14539&edit=1

« previous php.pear.dev (#3714) next »