Re: References - good or bad
| From: | Andi Gutmans | Date: | Sat, 29 Dec 2001 09:05:24 +0000 |
| Subject: | Re: References - good or bad | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-75236@lists.php.net to get a copy of this message | ||
At 08:20 AM 12/29/2001 +0800, Alan Knowles wrote:
Andi Gutmans wrote:To copy around a reference you will just use it as a regular value. Like in your second example, i.e.: $same_object = $object; Basically you're just copying the object handle and not the object itself. In order to create a real copy (with a new object handle) you'll do: $new_object = $object->__clone(); AndiAs I mentioned on the ZE2 mailing list there general rule of thumb is: a) Objects should be passed by reference. b) Everything else including arrays should be used by value whenever possible semantically. In the ZE2 objects will join b).Is there a proposed sytnax to stop copy by reference (Or did i miss it in the ZE2 docs) old stuff $object_copy = $object; //(copy) $object_copy = &$object; //(copy reference) new stuff? $object_copy = copy_object($object); //(copy????) $object_copy = $object; //(copy reference)