note 66899 added to language.oop.newref

From: Date: Wed, 31 May 2006 18:20:27 +0000
Subject: note 66899 added to language.oop.newref
Groups: php.notes 
Request: Send a blank email to php-notes+get-112668@lists.php.net to get a copy of this message
Note that the "new" operator no longer returns a copy of the constructed object, but the object itself. This behavior may be as of PHP 5.x. This means that $foo = new class(); and $foo =& new class(); are equivalent now, and you don't have to worry about the problems stated on this page. Consider the following example: <?php class foo { var $num; function foo() { global $globalref; $globalref[] = &$this; } } $bar = new foo(); $bar->num = 1; $globalref[0]->num = 2; echo "\$bar->num = ".$bar->num."\n"; echo "\$globalref[0]->num = ".$globalref[0]->num."\n"; ?> On PHP 5.0.1, it will print: $bar->num = 2 $globalref[0]->num = 2 Whereas on PHP 4.4.0, it would print: $bar->num = 1 $globalref[0]->num = 2 unless you assigned $bar to a new foo using a reference. ---- Server IP: 85.111.4.6 Probable Submitter: 195.174.67.207 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop.newref.php Edit -- http://master.php.net/note/edit/66899 Del: integrated -- http://master.php.net/note/delete/66899/integrated Del: useless -- http://master.php.net/note/delete/66899/useless Del: bad code -- http://master.php.net/note/delete/66899/bad+code Del: spam -- http://master.php.net/note/delete/66899/spam Del: non-english -- http://master.php.net/note/delete/66899/non-english Del: in docs -- http://master.php.net/note/delete/66899/in+docs Del: other reasons-- http://master.php.net/note/delete/66899 Reject -- http://master.php.net/note/reject/66899 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#112668) next »