NYCPHP Meetup

NYPHP.org

[nycphp-talk] newbie confusion

Adam Maccabee Trachtenberg adam at trachtenberg.com
Thu Nov 11 11:49:35 EST 2004


On Thu, 11 Nov 2004, Mitch Pirtle wrote:

> This behavior is changed by default in PHP5, and there are others on
> this list that are much more knowledgable on PHP5 than I.  I'm still
> trying to get Fedora Core 3 to install ;-)

In PHP 5, objects are passed (into and out of functions, etc) and
copied by reference. Everything else (scalars, strings, booleans,
etc.) behave the same and are passed by value.

To make a by-value copy of an object, use the clone operator:

$copy = clone $original;

To control the cloning behavior of a class, define a __clone() method.

More details available in "Upgrading to PHP 5." :)

-adam

-- 
adam at trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!



More information about the talk mailing list