$bar = 7;
$foo =& $bar = 9;
From a technical stand point, wouldn't this be evaluated from right to left? So: $bar = 9; $foo =& $bar
In case anyone is wondering. The reason I'm doing this on one line is to avoid toe nail clippings.
For passing variables by reference, it is necessary to add the ampersand ( & ) symbol before the argument of the variable. An example of such a function will look as follows: function( &$x ). The scope of the global and function variables becomes global. The reason is that they are defined by the same reference.
In PHP, there is a shortcut for appending a new string to the end of another string. This can be easily done with the string concatenation assignment operator ( . = ). This operator will append the value on its right to the value on its left and then reassign the result to the variable on its left.
PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it.
A variable starts with the $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character. A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
The assignment expression $bar = 9
doesn't return a reference to $bar
(i.e. the variable itself); instead, it returns the integer value 9
.
Or if you need a quote from the manual:
The value of an assignment expression is the value assigned. That is, the value of "$a = 3" is 3.
You can't assign a reference directly to a value, only to a variable that holds that value. So your handy one-liner fails spectacularly, and you'll have to split it into two.
For the very same reason that
$bar =& 9;
is not valid (because reference can point to another variable, but not constant / literal). See : http://www.php.net/manual/en/language.references.whatdo.php
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