Doc #80528 [Ver->Csd]: No waring/error for some nested ternary operators without explicit parentheses
| From: | phpdocbot@php.net | Date: | Thu, 17 Dec 2020 18:02:13 +0000 |
| Subject: | Doc #80528 [Ver->Csd]: No waring/error for some nested ternary operators without explicit parentheses | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18277@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
Updated by: phpdocbot@php.net
Reported by: andrew dot engdahl at gmail dot com
Summary: No waring/error for some nested ternary operators
without explicit parentheses
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: *General Issues
Operating System: All
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=4642b715f374b4220884fa110b6529ac948799b5
Log: Fix #80528: No waring/error for some nested ternary operators without explicit parentheses
Previous Comments:
------------------------------------------------------------------------
[2020-12-17 18:00:59] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=352118
Log: Fix #80528: No waring/error for some nested ternary operators without explicit parentheses
------------------------------------------------------------------------
[2020-12-17 16:22:10] nikic@php.net
Nesting into the middle operand is not affected, because it is unambiguous. See https://wiki.php.net/rfc/ternary_associativity
for precise rules.
Possibly the note in the migration guide needs to be more explicit?
------------------------------------------------------------------------
[2020-12-17 16:21:58] andrew dot engdahl at gmail dot com
Sorry in expected results the second version should be 8.0 instead of 7.8
------------------------------------------------------------------------
[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