Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 11a9b03

Browse files
committedOct 5, 2021
Fix duplicate undef warning in assign_dim_op
In case of auto-vivification we were fetching dim twice and as such also emitting the undef var warning twice.
1 parent f890c9c commit 11a9b03

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed
 

‎Zend/tests/assign_dim_op_undef.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Compound array assign with undefined variables
3+
--FILE--
4+
<?php
5+
$a[$b] += 1;
6+
var_dump($a);
7+
?>
8+
--EXPECTF--
9+
Warning: Undefined variable $a in %s on line %d
10+
11+
Warning: Undefined variable $b in %s on line %d
12+
13+
Warning: Undefined array key "" in %s on line %d
14+
array(1) {
15+
[""]=>
16+
int(1)
17+
}

‎Zend/zend_vm_def.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,8 @@ ZEND_VM_C_LABEL(assign_dim_op_new_array):
12021202
}
12031203
}
12041204

1205-
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
1206-
12071205
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
1206+
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
12081207
if (OP2_TYPE == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
12091208
dim++;
12101209
}
@@ -1216,6 +1215,7 @@ ZEND_VM_C_LABEL(assign_dim_op_new_array):
12161215
ZVAL_ARR(container, zend_new_array(8));
12171216
ZEND_VM_C_GOTO(assign_dim_op_new_array);
12181217
} else {
1218+
dim = GET_OP2_ZVAL_PTR(BP_VAR_R);
12191219
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
12201220
ZEND_VM_C_LABEL(assign_dim_op_ret_null):
12211221
FREE_OP_DATA();

‎Zend/zend_vm_execute.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22270,9 +22270,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_CONST_H
2227022270
}
2227122271
}
2227222272

22273-
dim = RT_CONSTANT(opline, opline->op2);
22274-
2227522273
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
22274+
dim = RT_CONSTANT(opline, opline->op2);
2227622275
if (IS_CONST == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
2227722276
dim++;
2227822277
}
@@ -22284,6 +22283,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_CONST_H
2228422283
ZVAL_ARR(container, zend_new_array(8));
2228522284
goto assign_dim_op_new_array;
2228622285
} else {
22286+
dim = RT_CONSTANT(opline, opline->op2);
2228722287
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
2228822288
assign_dim_op_ret_null:
2228922289
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -24777,9 +24777,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_TMPVAR_
2477724777
}
2477824778
}
2477924779

24780-
dim = _get_zval_ptr_var(opline->op2.var EXECUTE_DATA_CC);
24781-
2478224780
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
24781+
dim = _get_zval_ptr_var(opline->op2.var EXECUTE_DATA_CC);
2478324782
if ((IS_TMP_VAR|IS_VAR) == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
2478424783
dim++;
2478524784
}
@@ -24791,6 +24790,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_TMPVAR_
2479124790
ZVAL_ARR(container, zend_new_array(8));
2479224791
goto assign_dim_op_new_array;
2479324792
} else {
24793+
dim = _get_zval_ptr_var(opline->op2.var EXECUTE_DATA_CC);
2479424794
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
2479524795
assign_dim_op_ret_null:
2479624796
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -26958,9 +26958,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_UNUSED_
2695826958
}
2695926959
}
2696026960

26961-
dim = NULL;
26962-
2696326961
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
26962+
dim = NULL;
2696426963
if (IS_UNUSED == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
2696526964
dim++;
2696626965
}
@@ -26972,6 +26971,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_UNUSED_
2697226971
ZVAL_ARR(container, zend_new_array(8));
2697326972
goto assign_dim_op_new_array;
2697426973
} else {
26974+
dim = NULL;
2697526975
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
2697626976
assign_dim_op_ret_null:
2697726977
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -28677,9 +28677,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_CV_HAND
2867728677
}
2867828678
}
2867928679

28680-
dim = _get_zval_ptr_cv_BP_VAR_R(opline->op2.var EXECUTE_DATA_CC);
28681-
2868228680
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
28681+
dim = _get_zval_ptr_cv_BP_VAR_R(opline->op2.var EXECUTE_DATA_CC);
2868328682
if (IS_CV == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
2868428683
dim++;
2868528684
}
@@ -28691,6 +28690,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_VAR_CV_HAND
2869128690
ZVAL_ARR(container, zend_new_array(8));
2869228691
goto assign_dim_op_new_array;
2869328692
} else {
28693+
dim = _get_zval_ptr_cv_BP_VAR_R(opline->op2.var EXECUTE_DATA_CC);
2869428694
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
2869528695
assign_dim_op_ret_null:
2869628696
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -39265,9 +39265,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_CONST_HA
3926539265
}
3926639266
}
3926739267

39268-
dim = RT_CONSTANT(opline, opline->op2);
39269-
3927039268
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
39269+
dim = RT_CONSTANT(opline, opline->op2);
3927139270
if (IS_CONST == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
3927239271
dim++;
3927339272
}
@@ -39279,6 +39278,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_CONST_HA
3927939278
ZVAL_ARR(container, zend_new_array(8));
3928039279
goto assign_dim_op_new_array;
3928139280
} else {
39281+
dim = RT_CONSTANT(opline, opline->op2);
3928239282
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
3928339283
assign_dim_op_ret_null:
3928439284
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -42852,9 +42852,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_TMPVAR_H
4285242852
}
4285342853
}
4285442854

42855-
dim = _get_zval_ptr_var(opline->op2.var EXECUTE_DATA_CC);
42856-
4285742855
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
42856+
dim = _get_zval_ptr_var(opline->op2.var EXECUTE_DATA_CC);
4285842857
if ((IS_TMP_VAR|IS_VAR) == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
4285942858
dim++;
4286042859
}
@@ -42866,6 +42865,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_TMPVAR_H
4286642865
ZVAL_ARR(container, zend_new_array(8));
4286742866
goto assign_dim_op_new_array;
4286842867
} else {
42868+
dim = _get_zval_ptr_var(opline->op2.var EXECUTE_DATA_CC);
4286942869
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
4287042870
assign_dim_op_ret_null:
4287142871
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -45610,9 +45610,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_UNUSED_H
4561045610
}
4561145611
}
4561245612

45613-
dim = NULL;
45614-
4561545613
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
45614+
dim = NULL;
4561645615
if (IS_UNUSED == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
4561745616
dim++;
4561845617
}
@@ -45624,6 +45623,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_UNUSED_H
4562445623
ZVAL_ARR(container, zend_new_array(8));
4562545624
goto assign_dim_op_new_array;
4562645625
} else {
45626+
dim = NULL;
4562745627
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
4562845628
assign_dim_op_ret_null:
4562945629
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);
@@ -47863,9 +47863,8 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_CV_HANDL
4786347863
}
4786447864
}
4786547865

47866-
dim = _get_zval_ptr_cv_BP_VAR_R(opline->op2.var EXECUTE_DATA_CC);
47867-
4786847866
if (EXPECTED(Z_TYPE_P(container) == IS_OBJECT)) {
47867+
dim = _get_zval_ptr_cv_BP_VAR_R(opline->op2.var EXECUTE_DATA_CC);
4786947868
if (IS_CV == IS_CONST && Z_EXTRA_P(dim) == ZEND_EXTRA_VALUE) {
4787047869
dim++;
4787147870
}
@@ -47877,6 +47876,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ASSIGN_DIM_OP_SPEC_CV_CV_HANDL
4787747876
ZVAL_ARR(container, zend_new_array(8));
4787847877
goto assign_dim_op_new_array;
4787947878
} else {
47879+
dim = _get_zval_ptr_cv_BP_VAR_R(opline->op2.var EXECUTE_DATA_CC);
4788047880
zend_binary_assign_op_dim_slow(container, dim OPLINE_CC EXECUTE_DATA_CC);
4788147881
assign_dim_op_ret_null:
4788247882
FREE_OP((opline+1)->op1_type, (opline+1)->op1.var);

0 commit comments

Comments
 (0)
Please sign in to comment.