); $c = 6;
echo "$a - $b - $c<br>"; //$a is not exist but it was only pointer ( not real part of memory) so we have to way to get value or change it ?> ----
When we want create some "pointer of pointer" in PHP i can't do that because it's impossible in PHP. We need pointer to another pointer to change the place that the pointer refers to. In your exaple you just change value of variable in function. ( no operation of pointers )
russrobinson at tectite dot com (04-May-2010 05:22)
The example shown is correct for scalars.
However, in PHP5 the example does not cover objects, which behave the opposite of the way this documentation indicates.
It is my view that object references in PHP5 are exactly like pointers in C++.
This example code illustrates my point: <?php class Dog {
var $Name;
function Dog($name)
{ $this->Name = $name;
}
function GetName()
{
return ($this->Name);
}
};
$bar = new Dog("Spot");
function foo(&$var)
{ $var = new Dog("Gypsy");
} foo($bar);
echo "<p>".$bar->GetName();
echo "<p>"."If that said 'Gypsy', then object references are really pointers"; ?>
And the output is:
****
Gypsy
If that said 'Gypsy', then object references are really pointers
****
Therefore, corrected documentation should read (or similar):
"
Unless $bar is an object, there's no way to bind $bar in the calling scope to something else using the reference mechanism since $bar is not available in the function foo (it is represented by $var, but $var has only variable contents and not name-to-value binding in the calling symbol table).
If $bar is an object, then you can change $bar in the calling scope using the reference mechanism inside a function.
"
However, note that when I said:
"It is my view that object references in PHP5 are exactly like pointers in C++."
The "exactly like" part is misleading...
To clarify:
I don't mean PHP5 object references support pointer arithmetic or they contain memory addresses.
I mean that, in PHP5, when you pass object variables to functions they *behave* exactly like pointers to objects do in the same situation when writing in C++ (with the exception of the C++ features that just don't exist in PHP, such as pointer arithmetic).