is PHP and C++ the only 2 places that we need to careful about passing a simple data type variable as a function argument and the value can be changed?
such as
$count = 2;
foo($count);
echo $count;
and the 3rd line, echo $count display something other than 2. I only know of PHP and C++ where it can happen. Is there any other place where it can happen?
Update: that is, what looks like “pass by value” is in fact “pass by reference”. If it is passing an object in Java, Perl, PHP, Python, and Ruby, it is automatically pass-by-reference and the instance variables’ values of the object can be changed. What about passing in non-object?
Many other languages support such “pass by reference” — Perl, Fortran, Pascal, Visual Basic, …
Which ones you care about, well, it’s hard for us to say!-)
Edit:
In your update, you put Java and Python in the same category, but that’s wrong: you could not reproduce your example with (Java):
or (Python):
Python and Java’s style is sometimes known as “by object reference” (as opposed to “by variable reference”): what’s passed (or assigned) is a reference to the object (so IF the object has mutators the callee can invoke those mutators and thus alter the object), NOT to a “variable” (so that after the call the variable, if any, used to pass the argument, still refers to the same object, never to another object). This distinction is most clear to see with immutable objects, such as (in both Java and Python) numbers and strings.