References and new Objects
Posted: Fri Apr 04, 2003 1:59 pm
On PHP.net I was going over references again and I couldn't find anywhere that talked about using references on new objects. Example:
Okay, so rather than creating a new object and getting a copy of the object, I'm creating a new object and getting a reference to that object. I understand that. My question is, should I have an ampersand infront of the constructor for the class in order to be using this correctly? Which of the following code is correct, and if they are both correct, which is considered better programming.
Example 1:
Example 2:
The only difference between the two statements is the constructor definition.
Any input would be helpful.
Code: Select all
$newObject =& new objectClass();Example 1:
Code: Select all
class objectClass()
{
function &objectClass()
{
blah......
}
}
$newObject =& new objectClass();Code: Select all
class objectClass()
{
function objectClass()
{
blah......
}
}
$newObject =& new objectClass();Any input would be helpful.