It is not a moot point as it has consequences for upgrading. Consider this PHP4 script:
<?php
class Number {
var $n;
function Number($n = 0) {
$this->n = $n;
}
function value() {
return $this->n;
}
}
function add(&$x, $n) {
$x = new Number($x->value() + $n);
}
$num = new Number();
add($num, 123);
echo $num->value();
?>
When run, it produces the output of 123, as expected.
Now, the server gets upgraded to PHP5, and then the maintainer decides to upgrade the script as well. Due to a failure to understand the concept in question, the maintainer decides to remove the pass by reference since "passing objects to functions also passes them by reference by default":
<?php
class Number {
private $n;
function __construct($n = 0) {
$this->n = $n;
}
function value() {
return $this->n;
}
}
function add(Number $x, $n) {
$x = new Number($x->value() + $n);
}
$num = new Number();
add($num, 123);
echo $num->value();
?>
The output becomes 0, which is incorrect.