com php-src: Argument unpacking with Traversables and non-integer keys. Changed error message, added UPGRADING note and test.: UPGRADING
Zend/tests/arg_unpack/non_integer_keys.phpt Zend/zend _vm_def.h Zend/zend_vm_execute.h

From: Date: Wed, 04 Jul 2018 19:34:36 +0000
Subject: com php-src: Argument unpacking with Traversables and non-integer keys. Changed error message, added UPGRADING note and test.: UPGRADING
Zend/tests/arg_unpack/non_integer_keys.phpt Zend/zend _vm_def.h Zend/zend_vm_execute.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-102405@lists.php.net to get a copy of this message
Commit: 3a8f26060c44b86145f332e87c53668cac58a6d0 Author: Dmitry Stogov <dmitry@zend.com> Wed, 4 Jul 2018 22:34:36 +0300 Parents: 6337af09dc476ce6c5da951e7e01b4592d272531 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3a8f26060c44b86145f332e87c53668cac58a6d0 Log: Argument unpacking with Traversables and non-integer keys. Changed error message, added UPGRADING note and test. Changed paths: M UPGRADING A Zend/tests/arg_unpack/non_integer_keys.phpt M Zend/zend_vm_def.h M Zend/zend_vm_execute.h Diff: diff --git a/UPGRADING b/UPGRADING index f616bf9..e926cd1 100644 --- a/UPGRADING +++ b/UPGRADING @@ -80,6 +80,19 @@ Core: note that reading and writing a value inside a single expression remains undefined behavior and may change again in the future. + . Argument unpacking stopped working with Traversables with non-integer keys. + The following code worked in PHP 7.0-7.2 by accident. + + function foo(...$args) { + var_dump($args); + } + function gen() { + yield 1.23 => 123; + } + foo(...gen()); + + Now it generates an exception. + BCMath: . All warnings thrown by BCMath functions are now using PHP's error handling. Formerly some warnings have directly been written to stderr.. diff --git a/Zend/tests/arg_unpack/non_integer_keys.phpt b/Zend/tests/arg_unpack/non_integer_keys.phpt new file mode 100644 index 0000000..19ed61f --- /dev/null +++ b/Zend/tests/arg_unpack/non_integer_keys.phpt @@ -0,0 +1,21 @@ +--TEST-- +Argument unpacking does not work with non-integer keys +--FILE-- +<?php +function foo(...$args) { + var_dump($args); +} +function gen() { + yield 1.23 => 123; + yield "2..34" => 234; +} + +try { + foo(...gen()); +} catch (Error $ex) { + echo "Exception: " . $ex->getMessage() . "\n"; +} + +?> +--EXPECT-- +Exception: Cannot unpack Traversable with non-integer keys diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index c5ff50c..5fb94b1 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -4522,10 +4522,11 @@ ZEND_VM_C_LABEL(send_again): } if (UNEXPECTED(Z_TYPE(key) != IS_LONG)) { - ZEND_ASSERT(Z_TYPE(key) == IS_STRING); zend_throw_error(NULL, - "Cannot unpack Traversable with string keys"); - zval_ptr_dtor_str(&key); + (Z_TYPE(key) == IS_STRING) ? + "Cannot unpack Traversable with string keys" : + "Cannot unpack Traversable with non-integer keys"); + zval_ptr_dtor(&key); break; } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 2724bca..7aeb0a7 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -1359,10 +1359,11 @@ send_again: } if (UNEXPECTED(Z_TYPE(key) != IS_LONG)) { - ZEND_ASSERT(Z_TYPE(key) == IS_STRING); zend_throw_error(NULL, - "Cannot unpack Traversable with string keys"); - zval_ptr_dtor_str(&key); + (Z_TYPE(key) == IS_STRING) ? + "Cannot unpack Traversable with string keys" : + "Cannot unpack Traversable with non-integer keys"); + zval_ptr_dtor(&key); break; } }

« previous php.cvs (#102405) next »