Doc #80528 [Opn->Ver]: No waring/error for some nested ternary operators without explicit parentheses

From: Date: Thu, 17 Dec 2020 17:50:42 +0000
Subject: Doc #80528 [Opn->Ver]: 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-18276@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: cmb@php.net Reported by: andrew dot engdahl at gmail dot com Summary: No waring/error for some nested ternary operators without explicit parentheses -Status: Open +Status: Verified Type: Documentation Problem Package: *General Issues Operating System: All PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#18276) next »