diff --git a/NEWS b/NEWS index 19dbea1300b..d468ec1b74a 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ PHP NEWS property). (ilutov) . Fixed bug GH-19044 (Protected properties are not scoped according to their prototype). (Bob) + . Fixed bug GH-18581 (Coerce numeric string keys from iterators when argument + unpacking). (ilutov) - Hash: . Fix crash on clone failure. (nielsdos) diff --git a/Zend/tests/gh18581.phpt b/Zend/tests/gh18581.phpt new file mode 100644 index 00000000000..cc5c0fff02e --- /dev/null +++ b/Zend/tests/gh18581.phpt @@ -0,0 +1,32 @@ +--TEST-- +GH-18581: Coerce numeric string keys from iterators when argument unpacking +--FILE-- + 'first'; + yield '101' => 'second'; + yield '102' => 'third'; + yield 'named' => 'fourth'; +} + +function test($x = null, $y = null, ...$z) { + var_dump($x, $y, $z); + var_dump($z[0]); + var_dump($z['named']); +} + +test(...g()); + +?> +--EXPECT-- +string(5) "first" +string(6) "second" +array(2) { + [0]=> + string(5) "third" + ["named"]=> + string(6) "fourth" +} +string(5) "third" +string(6) "fourth" diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 01bdcf0ad6a..d80496f3022 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -5329,6 +5329,11 @@ ZEND_VM_C_LABEL(send_again): } name = Z_STR_P(&key); + + zend_ulong tmp; + if (ZEND_HANDLE_NUMERIC(name, tmp)) { + name = NULL; + } } } diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 96bdc01746a..a1c9831f8ce 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -2419,6 +2419,11 @@ send_again: } name = Z_STR_P(&key); + + zend_ulong tmp; + if (ZEND_HANDLE_NUMERIC(name, tmp)) { + name = NULL; + } } }