Page 1 of 1
What is the point of references in a new statement?
Posted: Sun Mar 14, 2004 5:28 am
by LonelyProgrammer
Example:
Code: Select all
class foobar() { ... }
$aFooBar = & new foobar();
How is it different from:
Read the docs on references...I still feel...kind of lost.
Posted: Sun Mar 14, 2004 11:06 am
by markl999
With the & you get a reference to the object, without it you get a copy. The question really is, why would you want a copy ? (btw, PHP5 will automatically give you a reference without the & )
Copy of the object...?
Posted: Mon Mar 15, 2004 8:11 am
by LonelyProgrammer
Wait a sec, I still don't get it. If I want a new instance of class, why would I want a reference to the class? Unless if you meant by copy, you are saying that PHP creates two copies whenver I use "$c = new classC();", one which is $c, and another one which is "new classC()" ?