note 8951 added to Classes and Objects

From: Date: Sun, 08 Oct 2000 21:12:40 +0000
Subject: note 8951 added to Classes and Objects
Groups: php.notes 
Request: Send a blank email to php-notes+get-6220@lists.php.net to get a copy of this message
Here's a very important reminder to those of you used to Java/C++ object references/pointers. When you send a function arguments which include a class object, PHP will make copies of that object for use inside that function. This differs from passing a Java reference to an object or passing a C++ pointer to an object. Within the scope of the above-mentioned function, calling class methods of the argument object will only affect the copy that PHP creates. Likewise, when the function itself is completed, the copy of the object you passed ceases to exist. To emulate Java/C++ functionality of arguments that are objects, you just have to modify the given function's signature from this: function foo(..., $object, ...) to this: function foo(..., &$object, ...) The ampersand(&) thus signifies that the function should receive a reference to the object, instead of creating a copy of the object. http://www.php.net/manual/language.oop.php

« previous php.notes (#6220) next »