Update: in
it says:
One of the key-points of PHP5 OOP that is often mentioned is that "objects are passed by references by default". This is not completely true.
Why is that? The following is a reason which I don't know is completely true or not:
I think loosely speaking, foo can be said to be an object, or an instance of the class Foo.
But is it true that very technically speaking, foo is just a reference, the exactly same way in Java and in Ruby, where variable foo
is always just a reference to an object.
So that's why in PHP,
function add($obj) {
$obj->a++;
}
We don't say "pass by reference", but very technically speaking, we are passing a value, which is a reference. So, it is "passing the reference", not "passing by reference".
But, if we say in PHP, that foo is an object, then I guess "passing by reference" can make sense. So is it true? foo is said to be a reference to an object, not an object, so that's why we are just "passing by value"?