NYCPHP Meetup

NYPHP.org

[nycphp-talk] I need a very elementary-school explanation of ' &'

Adam Maccabee Trachtenberg adam at trachtenberg.com
Thu Feb 19 16:50:11 EST 2004


On Thu, 19 Feb 2004, David Mintz wrote:

> Further -- again, pls correct me if I'm wrong, as I'm just the bat boy
> among the heavy hitters here -- PHP5 will pass/assign objects by reference
> *by default*, so you have to clone off a copy if you *don't* want that.
> The =& notation will become superfluous.

This is correct. In PHP 5, objects are passed and assigned by
reference and you need to use the clone operator to duplicate them.

$original = new van_gogh_painting;
$knock_off = clone $original;

You can control the cloning process by defining a __clone() method
inside the class; otherwise, you just get regular copy of all the
object properties.

-adam

-- 
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!



More information about the talk mailing list