Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP pointers vs references

In PHP, what is the difference between using a pointer such as:

function foo( $var )
{
    $var = 3;
}

$a = 0;
foo( &$a );

And reference:

function foo( &$var )
{
    $var = 3;
}

$a = 0;
foo( $a );

They both modify the value of the original variable, but are they represented differently internally?

like image 858
Sarathi Avatar asked Dec 27 '22 01:12

Sarathi


1 Answers

In PHP, there are no pointers, only references. Your examples demonstrate pass by reference

The difference between your code snippets is only in syntax, where the first syntax is now deprecated.

like image 138
Yogu Avatar answered Jan 13 '23 13:01

Yogu