Consider the following code.
$a = new stdClass(); $a->foo = 'foo'; $b = $a; echo $b->foo; // 'foo' of course. $a->foo = 'bar'; echo $b->foo; // 'bar'
$a = 'foo'; $b = $a; $a = 'bar'; echo $b; // foo;
You can pass by reference with the & operator though.
$a = 'foo'; $b =& $a; $a = 'bar'; echo $b; // bar;
Arguments to functions can be passed by reference or have their returns [url=http://php.net/manual/en/language.references.pass.php]received by reference. There are valid reasons for doing either of these but use this functionality with caution - misused it can lead to hard to debug code. Of particular concern is the practice of receiving a variable by reference, then changing it’s value. As a general rule a function shouldn’t change the program state in any way other than to issue its return, nor should it have any internal state. However, the technique of receiving by reference and then operating on the passed variables is used in the language itself with several of the array sorting methods ([fphp]sort[/fphp], [fphp]arsort[/fphp], etc). This is done to conserve memory.
For more information on references in PHP, click here.
For more information on objects and references in PHP, click here.