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.p
hp.net/note/edit/66899
Del: integrated -- ht
tp://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://m
aster.php.net/note/delete/66899/spam
Del: non-english -- h
ttp://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://ma
ster.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|