Skip to content

Commit 23ec35b

Browse files
committed
Coerce numeric string keys from iterators when argument unpacking
Fixes GH-18581 Closes GH-19151
1 parent 7efbb2e commit 23ec35b

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed GH-19169 build issue with C++17 and ZEND_STATIC_ASSERT macro.
77
(psumbera)
8+
. Fixed bug GH-18581 (Coerce numeric string keys from iterators when argument
9+
unpacking). (ilutov)
810

911
- Hash:
1012
. Fix crash on clone failure. (nielsdos)

Zend/tests/gh18581.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-18581: Coerce numeric string keys from iterators when argument unpacking
3+
--FILE--
4+
<?php
5+
6+
function g() {
7+
yield '100' => 'first';
8+
yield '101' => 'second';
9+
yield '102' => 'third';
10+
yield 'named' => 'fourth';
11+
}
12+
13+
function test($x = null, $y = null, ...$z) {
14+
var_dump($x, $y, $z);
15+
var_dump($z[0]);
16+
var_dump($z['named']);
17+
}
18+
19+
test(...g());
20+
21+
?>
22+
--EXPECT--
23+
string(5) "first"
24+
string(6) "second"
25+
array(2) {
26+
[0]=>
27+
string(5) "third"
28+
["named"]=>
29+
string(6) "fourth"
30+
}
31+
string(5) "third"
32+
string(6) "fourth"

Zend/zend_vm_def.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,6 +5236,11 @@ ZEND_VM_C_LABEL(send_again):
52365236
}
52375237

52385238
name = Z_STR_P(&key);
5239+
5240+
zend_ulong tmp;
5241+
if (ZEND_HANDLE_NUMERIC(name, tmp)) {
5242+
name = NULL;
5243+
}
52395244
}
52405245
}
52415246

Zend/zend_vm_execute.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)