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 /Zend | |
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.
Diffstat (limited to 'Zend')
-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 |
3 files changed, 29 insertions, 6 deletions
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; } } |