Re: HOWTO: &new notation OR Copy-by-Value

From: Date: Fri, 23 May 2003 11:18:24 +0000
Subject: Re: HOWTO: &new notation OR Copy-by-Value
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-5567@lists.php.net to get a copy of this message
marko wrote:
Hi, I just wanted to make sure that I do understand right: It looks like that many programmers use the wrong notation for objects created by "new", meaning stg like this: pointer = new Object();
PHP does not offer pointers. It's references you're talking about.
We actually create an object and COPY it into pointer. The proper way to do that would be rather pointer = & new Object(); This makes sure we work on the newly created object rather than on a copy of that. Saves memory, prevents problems concerning data integrity and so on and so forth.
'This is because "new" does not return a reference by default, instead it returns a copy.
    Note: There is no performance loss (since PHP 4 and up use reference counting) returning copies instead of references. On the contrary it is most often better to simply work with copies instead of references, because creating references takes some time where creating copies virtually takes no time (unless none of them is a large array or object and one of them gets changed and the other(s) one(s) subsequently, then it would be wise to use references to change them all concurrently). '
http://www.php.net/manual/en/language.oop.newref.php
Is it the policy to leave the situation as is and don't change anything, and just wait for PHP5 which would by definition only assign the reference?
Well, I'd prefer wasting my time on a sunny balcony instead of modifing tons of existing code and turn all changes back as soon as PHP 5 on the horizon. Ulf

« previous php.pear.general (#5567) next »