com php-src: Fixed bug #80334: NEWS Zend/tests/named_params/a ssert.phpt Zend/zend_compile.c
| From: | Nikita Popov | Date: | Mon, 09 Nov 2020 09:19:32 +0000 |
| Subject: | com php-src: Fixed bug #80334: NEWS Zend/tests/named_params/a ssert.phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114086@lists.php.net to get a copy of this message | ||
Commit: 6fb3d92525d28f0b617a53d05a6be74a3ef37fa5
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 9 Nov 2020 10:18:43 +0100
Parents: 4bbe55b25078a1b5176faaf207aecb69be9811c8
Branches: PHP-8.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6fb3d92525d28f0b617a53d05a6be74a3ef37fa5
Log:
Fixed bug #80334
If assert() was called with named args, add description as named
arg as well.
Bugs:
https://bugs.php.net/80334
Changed paths:
M NEWS
A Zend/tests/named_params/assert.phpt
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index 9e7efeaf974..2039265620c 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.0.0RC4
+- Core:
+ . Fixed bug #80334 (assert() vs named parameters - confusing error). (Nikita)
+
- FFI:
. Fixed bug #79177 (FFI doesn't handle well PHP exceptions within callback).
(cmb, Dmitry, Nikita)
diff --git a/Zend/tests/named_params/assert.phpt b/Zend/tests/named_params/assert.phpt
new file mode 100644
index 00000000000..40a92a2f1fe
--- /dev/null
+++ b/Zend/tests/named_params/assert.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Calling assert with named params
+--FILE--
+<?php
+
+assert(assertion: true);
+try {
+ assert(assertion: false);
+} catch (AssertionError $e) {
+ echo $e->getMessage(), "\n";
+}
+
+assert(assertion: true, description: "Description");
+try {
+ assert(assertion: false, description: "Description");
+} catch (AssertionError $e) {
+ echo $e->getMessage(), "\n";
+}
+
+try {
+ assert(description: "Description");
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+assert(assertion: false)
+Description
+Named parameter $description overwrites previous argument
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 396cfd91c0c..dbb21944371 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3944,13 +3944,18 @@ static void zend_compile_assert(znode *result, zend_ast_list *args,
zend_string
}
opline->result.num = zend_alloc_cache_slot();
- if (args->children == 1 &&
- (args->child[0]->kind != ZEND_AST_ZVAL ||
- Z_TYPE_P(zend_ast_get_zval(args->child[0])) != IS_STRING)) {
+ if (args->children == 1) {
/* add "assert(condition) as assertion message */
- zend_ast_list_add((zend_ast*)args,
- zend_ast_create_zval_from_str(
- zend_ast_export("assert(", args->child[0], ")")));
+ zend_ast *arg = zend_ast_create_zval_from_str(
+ zend_ast_export("assert(", args->child[0], ")"));
+ if (args->child[0]->kind == ZEND_AST_NAMED_ARG) {
+ /* If the original argument was named, add the new argument as named as well,
+ * as mixing named and positional is not allowed.. */
+ zend_ast *name = zend_ast_create_zval_from_str(
+ zend_string_init("description", sizeof("description") - 1, 0));
+ arg = zend_ast_create(ZEND_AST_NAMED_ARG, name, arg);
+ }
+ zend_ast_list_add((zend_ast *) args, arg);
}
zend_compile_call_common(result, (zend_ast*)args, fbc);