Possible Duplicate:
Reference - What does this symbol mean in PHP?
what is the meaning of &$variable
and meaning of functions like
function &SelectLimit( $sql, $nrows=-1, $offset=-1, $inputarr=false, $secs2cache=0 )
{
$rs =& $this->do_query( $sql, $offset, $nrows, $inputarr);
return $rs;
}
1. something used for or regarded as representing something else; a material object representing something, often something immaterial; emblem, token, or sign. 2. a letter, figure, or other character or mark or a combination of letters or the like used to designate something.
1a : the thing one intends to convey especially by language : purport Do not mistake my meaning. b : the thing that is conveyed especially by language : import Many words have more than one meaning. 2 : something meant or intended : aim a mischievous meaning was apparent.
\ ˈ(h)wen , (h)wən \ Definition of when (Entry 2 of 4) 1a : at or during the time that : while went fishing when he was a boy.
An antonym is a word that is the opposite of another word. An opposite can be the other side of, reverse of, or something contrary to anything, not just words.
Passing an argument like so: myFunc(&$var);
means that the variable is passed by reference (and not by value). So any modifications made to the variable in the function modify the variable where the call is made.
Putting &
before the function name means "return by reference". This is a bit very counter-intuitive. I would avoid using it if possible. What does it mean to start a PHP function with an ampersand?
Be careful not to confuse it with the &=
or &
operator, which is completely different.
Quick test for passing by reference:
<?php
class myClass {
public $var;
}
function incrementVar($a) {
$a++;
}
function incrementVarRef(&$a) { // not deprecated
$a++;
}
function incrementObj($obj) {
$obj->var++;
}
$c = new myClass();
$c->var = 1;
$a = 1; incrementVar($a); echo "test1 $a\n";
$a = 1; incrementVar(&$a); echo "test2 $a\n"; // deprecated
$a = 1; incrementVarRef($a); echo "test3 $a\n";
incrementObj($c); echo "test4 $c->var\n";// notice that objects are
// always passed by reference
Output:
Deprecated: Call-time pass-by-reference has been deprecated; If you would like
to pass it by reference, modify the declaration of incrementVar(). [...]
test1 1
test2 2
test3 2
test4 2
The ampersand - "&" - is used to designate the address of a variable, instead of it's value. We call this "pass by reference".
So, "&$variable" is the reference to the variable, not it's value. And "function &func(..." tells the function to return the reference of the return variable, instead of a copy of the variable.
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With