This was deprecated in PHP 7.4.
recognized as a namespaced name, `Foo \ Bar` will not. Conversely, reserved
keywords are now permitted as namespace segments.
RFC: https://wiki.php.net/rfc/namespaced_names_as_token
+ . Nested ternaries now require explicit parentheses.
+ RFC: https://wiki.php.net/rfc/ternary_associativity
- COM:
. Removed the ability to import case-insensitive constants from type
--TEST--
-Using ternary associativity is deprecated
+Allowed nested ternary cases
--FILE--
<?php
-1 ? 2 : 3 ? 4 : 5; // deprecated
(1 ? 2 : 3) ? 4 : 5; // ok
1 ? 2 : (3 ? 4 : 5); // ok
-// While the associativity of ?: is also incorrect, it will not cause a
-// functional difference, only some unnecessary checks.
1 ?: 2 ?: 3; // ok
(1 ?: 2) ?: 3; // ok
1 ?: (2 ?: 3); // ok
-1 ?: 2 ? 3 : 4; // deprecated
(1 ?: 2) ? 3 : 4; // ok
1 ?: (2 ? 3 : 4); // ok
-1 ? 2 : 3 ?: 4; // deprecated
(1 ? 2 : 3) ?: 4; // ok
1 ? 2 : (3 ?: 4); // ok
?>
---EXPECTF--
-Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in %s on line 3
-
-Deprecated: Unparenthesized `a ?: b ? c : d` is deprecated. Use either `(a ?: b) ? c : d` or `a ?: (b ? c : d)` in %s on line 13
-
-Deprecated: Unparenthesized `a ? b : c ?: d` is deprecated. Use either `(a ? b : c) ?: d` or `a ? b : (c ?: d)` in %s on line 17
+===DONE===
+--EXPECT--
+===DONE===
--- /dev/null
+--TEST--
+Forbidden nested ternary, case 1
+--FILE--
+<?php
+
+1 ? 2 : 3 ? 4 : 5;
+
+?>
+--EXPECTF--
+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 %s on line %d
--- /dev/null
+--TEST--
+Forbidden nested ternary, case 2
+--FILE--
+<?php
+
+1 ?: 2 ? 3 : 4;
+
+?>
+--EXPECTF--
+Fatal error: Unparenthesized `a ?: b ? c : d` is not supported. Use either `(a ?: b) ? c : d` or `a ?: (b ? c : d)` in %s on line %d
--- /dev/null
+--TEST--
+Forbidden nested ternary, case 3
+--FILE--
+<?php
+
+1 ? 2 : 3 ?: 4;
+
+?>
+--EXPECTF--
+Fatal error: Unparenthesized `a ? b : c ?: d` is not supported. Use either `(a ? b : c) ?: d` or `a ? b : (c ?: d)` in %s on line %d
&& cond_ast->attr != ZEND_PARENTHESIZED_CONDITIONAL) {
if (cond_ast->child[1]) {
if (true_ast) {
- zend_error(E_DEPRECATED,
- "Unparenthesized `a ? b : c ? d : e` is deprecated. "
+ zend_error(E_COMPILE_ERROR,
+ "Unparenthesized `a ? b : c ? d : e` is not supported. "
"Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)`");
} else {
- zend_error(E_DEPRECATED,
- "Unparenthesized `a ? b : c ?: d` is deprecated. "
+ zend_error(E_COMPILE_ERROR,
+ "Unparenthesized `a ? b : c ?: d` is not supported. "
"Use either `(a ? b : c) ?: d` or `a ? b : (c ?: d)`");
}
} else {
if (true_ast) {
- zend_error(E_DEPRECATED,
- "Unparenthesized `a ?: b ? c : d` is deprecated. "
+ zend_error(E_COMPILE_ERROR,
+ "Unparenthesized `a ?: b ? c : d` is not supported. "
"Use either `(a ?: b) ? c : d` or `a ?: (b ? c : d)`");
} else {
/* This case is harmless: (a ?: b) ?: c always produces the same result