Bug #73919 [Ver->Nab]: Short ternary operator and reference
| From: | nikic@php.net | Date: | Thu, 12 Jan 2017 13:37:19 +0000 |
| Subject: | Bug #73919 [Ver->Nab]: Short ternary operator and reference | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206559@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73919&edit=1
ID: 73919
Updated by: nikic@php.net
Reported by: p17 at ivaldi dot xyz
Summary: Short ternary operator and reference
-Status: Verified
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 4.8.0-2-amd64
PHP Version: 7.1.0
Block user comment: N
Private report: N
New Comment:
Your code is equivalent to ($val =& $foo) ?: 'default' and behaves accordingly. The
RHS of a by-reference assignment must be variable-like, so this is the only valid way of parsing the
code.
We could relax the RHS to be an expression and impose the variable-like constraint subsequently.
However, this would be a backwards-incompatible change. The current parsing is consistent with our
treatment of variables in other circumstances, e.g. !$x instanceof y parses as !($x instanceof y)
rather than (!$x) instanceof y, because the LHS of instanceof must be variable-like.
Previous Comments:
------------------------------------------------------------------------
[2017-01-12 13:13:01] cmb@php.net
Confirmed: <https://3v4l.org/IU2Cq#v560>.
------------------------------------------------------------------------
[2017-01-12 12:54:29] p17 at ivaldi dot xyz
Description:
------------
Using the short tertiary operator ?: with a pointer as first condition results in a non expected
result.
Test script:
---------------
#!/usr/bin/php
<?php
error_reporting(E_ALL | E_STRICT);
$val = &$foo ?: 'default';
var_dump($val);
Expected result:
----------------
string(7) "default"
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73919&edit=1