PHP passes function arguments by value by default, meaning changes to a variable inside a function do not affect it outside. To pass by reference, use an ampersand when calling the function so changes inside the function also change the variable outside. References in PHP are not like pointers in C - they are aliases and do not represent memory addresses. PHP uses copy-on-write and reference counting to manage memory, only copying variable values when they are changed.
3. PHP
By default, function arguments are passed by value (so that
if the value of the argument within the function is changed, it
does not get changed outside of the function).
http://php.net/manual/en/functions.arguments.php
6. C ?
void foo(int var)
{
var++;
}
void main()
{
int a = 5;
foo(a);
/* a is 5 here */
}
7. PHP
You can pass a variable by reference to a function so the
function can modify the variable. The syntax is as follows:
http://php.net/manual/en/language.references.pass.php
10. C ?
void foo(int* var)
{
(*var)++;
}
void main()
{
int a = 5;
foo(&a);
/* a is 6 here */
}
11. PHP
References in PHP are a means to access the same
variable content by different names. They are not like C
pointers; for instance, you cannot perform pointer arithmetic
using them, they are not actual memory addresses, and so
on.
http://php.net/manual/en/language.references.whatare.php
13. C ?
References in PHP are a means to access the same variable
content by different names. They are not like C pointers;
for instance, you cannot perform pointer arithmetic using
them, they are not actual memory addresses, and so on.
http://php.net/manual/en/language.references.whatare.php
17. PHP copy-on-write
PHP is a dynamic, loosely typed language, that uses copy-
on-write and reference counting.
http://php.net/manual/en/internals2.variables.intro.php