Bug #80528 [NEW]: 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:17:31 +0000 |
| Subject: | Bug #80528 [NEW]: No waring/error for some nested ternary operators without explicit parentheses | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-231136@lists.php.net to get a copy of this message | ||
From: andrew dot engdahl at gmail dot com
Operating system: All
PHP version: Irrelevant
Package: *General Issues
Bug Type: Bug
Bug description:No waring/error for some nested ternary operators without explicit parentheses
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 bug report at https://bugs.php.net/bug.php?id=80528&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80528&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80528&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80528&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80528&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80528&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80528&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80528&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80528&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80528&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80528&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80528&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80528&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80528&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80528&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80528&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80528&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80528&r=mysqlcfg