function &test () { $data = ' Test '; Return (Is_null ($data)? $data: $data); if (Is_null ($data)) return $data; else return $data;} $s = Test (); Var_dump ($s);
This is to illustrate my intentions, the actual application is much more complex. function returns a reference, but I find that if you use the three-mesh operator to express it, PHP does not correctly understand the return, which appears
PHP Notice: Only variable references should is returned by reference
and swap with If, everything is fine.
Do not know this is not a bug, because there must be a lot of people found, and I used the 5.4.11, 5.5.0alpha4 have this problem
Reply to discussion (solution)
Also found in the manual:
Note: Notice that the ternary operator is a statement, so its evaluation is not a variable, but rather a result of the statement. This is important if you want to return a variable by reference. In a function returned by reference, return $var = = 42? $a: $b; Will not work, a warning will be issued for future versions of PHP.
Knot Stickers
It's not bug!. But the correct grammatical parsing.
Your function &test () declares that a reference is returned. Since it is a reference, it is necessary to have a quoted carrier.
The three-mesh operation is a structure whose result must be assigned to a real variable
$a = Is_null ($data)? $data: $data;
return $a;
There will be no mistakes.
Of course, function test () does not go wrong
Since php5.3, many of the early programs have this problem