Bug #80528 [Opn]: No waring/error for some nested ternary operators without explicit parentheses
| From: | andrew dot engdahl at gmail dot com | Date: | Thu, 17 Dec 2020 16:21:58 +0000 |
| Subject: | Bug #80528 [Opn]: No waring/error for some nested ternary operators without explicit parentheses | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231137@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80528&edit=1
ID: 80528
User updated by: andrew dot engdahl at gmail dot com
Reported by: andrew dot engdahl at gmail dot com
Summary: No waring/error for some nested ternary operators
without explicit parentheses
Status: Open
Type: Bug
Package: *General Issues
Operating System: All
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Sorry in expected results the second version should be 8.0 instead of 7.8
Previous Comments:
------------------------------------------------------------------------
[2020-12-17 16:17:31] andrew dot engdahl at gmail dot com
Description:
------------
As of 7.4 nested ternary operators without explicit parentheses are supposed to be deprecated.
However, this is only true with the following syntax:
$test = $cond1 ? 1 : $cond2 ? 2 : 3; // Raises warning
$test = $cond1 ? 1 : ( $cond2 ? 2 : 3 ); // Documented correct syntax https://www.php.net/manual/en/migration74.deprecated.php
If the secondary condition is nested within the first condition's true expression no warning or
error is raised
$test = $cond1 ? $cond2 ? 1 : 2 : 3; // No warning or error.
$cond1 = true & $cond2 = true returns 1
$cond1 = true & $cond2 = false returns 2
$cond1 = false returns 3
Test script:
---------------
$test = true ? true ? 1 : 2 : 3;
echo $test;
Expected result:
----------------
For 7.4
Deprecated: Unparenthesized
a ? b : c ? d : e is deprecated. Use either (a ? b :
c) ? d : e or a ? b : (c ? d : e) in /in/V9r8u on line 1
For 7.8
Fatal error: Unparenthesized a ? b : c ? d : e is not supported. Use either (a ?
b : c) ? d : e or a ? b : (c ? d : e) in /in/V9r8u on line 1
Actual result:
--------------
No warning or error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80528&edit=1