|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, 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)
--- /dev/null
+--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
}
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);