php

Copying objects in PHP 5 using clone

In PHP 4 object variables were simple. Assigning one object to another worked exactly as you'd expect.

$object1->title = "Title One";
$object2 = $object1;
$object2->title = "Title Two";
print $object1->title; // returns "Title One"

You could make a copy of the original, and modify your copy with full assurance that your original would remain untouched.

That changed in PHP 5. Now when you assign an object to a new variable.

Testing a few lines of PHP

Did you ever need to test just a few lines of PHP without wanting to bootstrap your entire script or application? Try using PHP's interactive shell on the command line using the -a option.

Tags: