Does this count as a bug?

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.