Skip to content

Commit e622c1a

Browse files
committed
Fix by-ref unpack sending of offsets
Fixes phpGH-12404
1 parent d2a9edf commit e622c1a

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Zend/tests/arg_unpack/gh14202.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-14202: Fetch splat arg value by RW
3+
--FILE--
4+
<?php
5+
$args = [1];
6+
$ref = [&$args];
7+
function test(&$v) {
8+
$v = 7;
9+
};
10+
test(...$ref[0]);
11+
var_dump($args[0]);
12+
?>
13+
--EXPECT--
14+
int(7)

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3685,7 +3685,11 @@ static uint32_t zend_compile_args(
36853685
uses_arg_unpack = 1;
36863686
fbc = NULL;
36873687

3688-
zend_compile_expr(&arg_node, arg->child[0]);
3688+
if (zend_is_variable(arg->child[0])) {
3689+
zend_compile_var(&arg_node, arg->child[0], BP_VAR_RW, /* by_ref */ false);
3690+
} else {
3691+
zend_compile_expr(&arg_node, arg->child[0]);
3692+
}
36893693
opline = zend_emit_op(NULL, ZEND_SEND_UNPACK, &arg_node, NULL);
36903694
opline->op2.num = arg_count;
36913695
opline->result.var = EX_NUM_TO_VAR(arg_count - 1);

Zend/zend_vm_def.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5114,7 +5114,12 @@ ZEND_VM_HANDLER(165, ZEND_SEND_UNPACK, ANY, ANY)
51145114
uint32_t arg_num;
51155115

51165116
SAVE_OPLINE();
5117-
args = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
5117+
5118+
if (OP1_TYPE == IS_VAR) {
5119+
args = GET_OP1_ZVAL_PTR_PTR_UNDEF(BP_VAR_RW);
5120+
} else {
5121+
args = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
5122+
}
51185123
arg_num = ZEND_CALL_NUM_ARGS(EX(call)) + 1;
51195124

51205125
ZEND_VM_C_LABEL(send_again):

Zend/zend_vm_execute.h

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)