On 9/23/07, Craig Constantine <cconstantine php.net> wrote:
> --On September 21, 2007 Sep 21, 15:16.43 +0000 PEAR
Announce
> <pear-dev lists.php.net> wrote:
>
> > * Replaced instances of '=& new Foo' with '=
new Foo' to make DB (slightly)
> > more E_STRICT friendly. Request 11581.
>
> All,
>
> Could someone hit me with the clue-bat on this. just
send me off to rtfm if
> this is explained clearly in one spot.
>
> I know that "$x =& new Foo()" is 'out' in
php5.
>
> but in PHP4, the "$x =& new Foo"
construct used to make a new Foo instance,
> then make $x refer to that instance. And "$x = new
Foo" use to make a new Foo,
> then make $x be a *copy* of that new Foo. I have this
vague recollection of
> falling over this in some project. I had used the
"$x = new Foo" contruct and
> took me a while to discover there were really two Foo
instances in that one
> line of code. When I changed to =& my problem was
resolved. So I dutifully
> started "=& new" all my objects in php4
>
This is exactly why I have always used =& in my PHP4
code. You can
introduce subtle bugs if you don't use it, such as if, in
the
constructor, a reference to the object that is being
instantiated is
stored somewhere (such as in a sub-class). Various PEAR
classes *will*
break if code is changed to use = rather than =&.
> so my questions:
>
> - is my understanding above, in php4 context, correct?
(I have legacty code to
> maintain ya know.)
>
> - and how does "$x = new Foo" work in php5?
does it 'just work correctly' thus
> we no longer needed the "$x =& new Foo"
from php4.
>
--
Justin Patrin
--
PEAR Development Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|