PHP's =& operator
这两个PHP语句是否做同样的事情?:
$o =& $thing;
$o = &$thing;
Yes, they are both the exact same thing. They just take the reference of the object and reference it within the variable $o
. Please note, thing
should be variables.
They're not the same thing, syntactically speaking. The operator is the atomic =& and this actually matters. For instance you can't use the =& operator in a ternary expression. Neither of the following are valid syntax:
$f = isset($field[0]) ? &$field[0] : &$field;
$f =& isset($field[0]) ? $field[0] : $field;
So instead you would use this:
isset($field[0]) ? $f =& $field[0] : $f =& $field;
They both give an expected T_PAAMAYIM_NEKUDOTAYIM error.
If you meant $o = &$thing;
then that assigns the reference of thing to o. Here's an example:
$thing = "foo";
$o = &$thing;
echo $o; // echos foo
$thing = "bar";
echo $o; // echos bar
链接地址: http://www.djcxy.com/p/58890.html
上一篇: SQL逻辑运算符优先级:和和或
下一篇: PHP的=&运营商