com php-src: Make nested ternary without parentheses a compile error: UPGRADING Zend/tests/ternary_associativity.phpt Zend/test
s/ternary_associativity_1.phpt Zend/tests/ternary_a ssociativity_2.phpt Zend/tests/ternary_associativity _3.phpt Zend/zend_compile.c
| From: | Nikita Popov | Date: | Fri, 24 Jul 2020 08:35:42 +0000 |
| Subject: | com php-src: Make nested ternary without parentheses a compile error: UPGRADING Zend/tests/ternary_associativity.phpt Zend/test s/ternary_associativity_1.phpt Zend/tests/ternary_a ssociativity_2.phpt Zend/tests/ternary_associativity _3.phpt Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-112354@lists.php.net to get a copy of this message | ||
Commit: 0a5b7c81b705869618755ed2d559702be6f9d6e4
Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 24 Jul 2020 10:35:03 +0200
Parents: 9bf119832dbf625174794834c71b1e793450d87f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0a5b7c81b705869618755ed2d559702be6f9d6e4
Log:
Make nested ternary without parentheses a compile error
This was deprecated in PHP 7.4.
Changed paths:
M UPGRADING
M Zend/tests/ternary_associativity.phpt
A Zend/tests/ternary_associativity_1.phpt
A Zend/tests/ternary_associativity_2.phpt
A Zend/tests/ternary_associativity_3.phpt
M Zend/zend_compile.c
Diff:
diff --git a/UPGRADING b/UPGRADING
index 85931d11cf..bf4584bb8e 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -208,6 +208,8 @@ PHP 8.0 UPGRADE NOTES
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
diff --git a/Zend/tests/ternary_associativity.phpt b/Zend/tests/ternary_associativity.phpt
index 32326513ca..edc0499143 100644
--- a/Zend/tests/ternary_associativity.phpt
+++ b/Zend/tests/ternary_associativity.phpt
@@ -1,30 +1,22 @@
--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===
diff --git a/Zend/tests/ternary_associativity_1.phpt b/Zend/tests/ternary_associativity_1.phpt
new file mode 100644
index 0000000000..87dc3972d2
--- /dev/null
+++ b/Zend/tests/ternary_associativity_1.phpt
@@ -0,0 +1,10 @@
+--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
diff --git a/Zend/tests/ternary_associativity_2.phpt b/Zend/tests/ternary_associativity_2.phpt
new file mode 100644
index 0000000000..c311e7cab4
--- /dev/null
+++ b/Zend/tests/ternary_associativity_2.phpt
@@ -0,0 +1,10 @@
+--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
diff --git a/Zend/tests/ternary_associativity_3.phpt b/Zend/tests/ternary_associativity_3.phpt
new file mode 100644
index 0000000000..c519e1fc0f
--- /dev/null
+++ b/Zend/tests/ternary_associativity_3.phpt
@@ -0,0 +1,10 @@
+--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
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index c21fb419b9..51849a2f94 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -8234,18 +8234,18 @@ void zend_compile_conditional(znode *result, zend_ast *ast) /* {{{ */
&& 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