#36357 [Asn->Bgs]: $tmp =& $this; is allowed!

From: Date: Mon, 13 Feb 2006 09:31:56 +0000
Subject: #36357 [Asn->Bgs]: $tmp =& $this; is allowed!
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93196@lists.php.net to get a copy of this message
ID: 36357 Updated by: dmitry@php.net Reported By: dams@php.net -Status: Assigned +Status: Bogus Bug Type: Class/Object related Operating System: Any PHP Version: 5.1.2 Assigned To: dmitry New Comment: $tmp =& $this is proper code (it can be dangerous, but this doesn't mean improper). Removing support for assignment and passing $this by reference will break a lot of existing PHP scripts. Previous Comments: ------------------------------------------------------------------------ [2006-02-10 17:05:54] dams@php.net Description: ------------ Using =&, it is possible to modify $this with the constructor. This shouldn't be allowed, just like for $tmp = $this; Reproduce code: --------------- <?php class B { function B() { } } class A { function A() { $tmp =& $this; var_dump($this); // outputs : object(A) $tmp = new B(); var_dump($this); // outputs : object(B) } } $a = new A(); var_dump($a); // outputs : object(A) ?> Expected result: ---------------- object(A)#1 (0) { } object(A)#2 (0) { } object(A)#1 (0) { } // current result : object(A)#1 (0) { } object(B)#2 (0) { } object(A)#1 (0) { } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36357&edit=1

« previous php.bugs (#93196) next »