diff options
author | Dmitry Stogov <dmitry@zend.com> | 2018-07-04 22:34:36 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2018-07-04 22:34:36 +0300 |
commit | 3a8f26060c44b86145f332e87c53668cac58a6d0 (patch) | |
tree | 2468a8e77f17d607064e0a796e47b51190c179fd | |
parent | 6337af09dc476ce6c5da951e7e01b4592d272531 (diff) | |
download | php-git-3a8f26060c44b86145f332e87c53668cac58a6d0.tar.gz |
Argument unpacking with Traversables and non-integer keys.
Changed error message, added UPGRADING note and test.
-rw-r--r-- | UPGRADING | 13 | ||||
-rw-r--r-- | Zend/tests/arg_unpack/non_integer_keys.phpt | 21 | ||||
-rw-r--r-- | Zend/zend_vm_def.h | 7 | ||||
-rw-r--r-- | Zend/zend_vm_execute.h | 7 |
4 files changed, 42 insertions, 6 deletions
@@ -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 0000000000..19ed61f2ee --- /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 c5ff50cf85..5fb94b142e 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 2724bca69c..7aeb0a7d39 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; } } |