Skip to content

Commit 776726d

Browse files
committed
Add missing resource key warning for unset()
It was present on other operations, including isset(), but was missing for unset().
1 parent 1954e59 commit 776726d

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Zend/tests/resource_key.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Behavior of resources as array keys
3+
--FILE--
4+
<?php
5+
6+
$r = fopen(__FILE__, 'r');
7+
$a = [];
8+
echo "Assign:";
9+
$a[$r] = 1;
10+
echo "Add assign:";
11+
$a[$r] += 1;
12+
echo "Inc:";
13+
$a[$r]++;
14+
echo "Get:";
15+
var_dump($a[$r]);
16+
echo "Isset:";
17+
var_dump(isset($a[$r]));
18+
echo "Unset:";
19+
unset($a[$r]);
20+
21+
?>
22+
--EXPECTF--
23+
Assign:
24+
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
25+
Add assign:
26+
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
27+
Inc:
28+
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
29+
Get:
30+
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
31+
int(3)
32+
Isset:
33+
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
34+
bool(true)
35+
Unset:
36+
Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d

Zend/zend_vm_def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6396,6 +6396,7 @@ ZEND_VM_C_LABEL(num_index_dim):
63966396
hval = 1;
63976397
ZEND_VM_C_GOTO(num_index_dim);
63986398
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
6399+
zend_use_resource_as_offset(offset);
63996400
hval = Z_RES_HANDLE_P(offset);
64006401
ZEND_VM_C_GOTO(num_index_dim);
64016402
} else if (OP2_TYPE == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {

Zend/zend_vm_execute.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24382,6 +24382,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_CONST_HANDL
2438224382
hval = 1;
2438324383
goto num_index_dim;
2438424384
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
24385+
zend_use_resource_as_offset(offset);
2438524386
hval = Z_RES_HANDLE_P(offset);
2438624387
goto num_index_dim;
2438724388
} else if (IS_CONST == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {
@@ -26532,6 +26533,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_TMPVAR_HAND
2653226533
hval = 1;
2653326534
goto num_index_dim;
2653426535
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
26536+
zend_use_resource_as_offset(offset);
2653526537
hval = Z_RES_HANDLE_P(offset);
2653626538
goto num_index_dim;
2653726539
} else if ((IS_TMP_VAR|IS_VAR) == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {
@@ -30543,6 +30545,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_VAR_CV_HANDLER(
3054330545
hval = 1;
3054430546
goto num_index_dim;
3054530547
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
30548+
zend_use_resource_as_offset(offset);
3054630549
hval = Z_RES_HANDLE_P(offset);
3054730550
goto num_index_dim;
3054830551
} else if (IS_CV == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {
@@ -41807,6 +41810,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_CONST_HANDLE
4180741810
hval = 1;
4180841811
goto num_index_dim;
4180941812
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
41813+
zend_use_resource_as_offset(offset);
4181041814
hval = Z_RES_HANDLE_P(offset);
4181141815
goto num_index_dim;
4181241816
} else if (IS_CONST == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {
@@ -45250,6 +45254,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_TMPVAR_HANDL
4525045254
hval = 1;
4525145255
goto num_index_dim;
4525245256
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
45257+
zend_use_resource_as_offset(offset);
4525345258
hval = Z_RES_HANDLE_P(offset);
4525445259
goto num_index_dim;
4525545260
} else if ((IS_TMP_VAR|IS_VAR) == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {
@@ -50372,6 +50377,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_UNSET_DIM_SPEC_CV_CV_HANDLER(Z
5037250377
hval = 1;
5037350378
goto num_index_dim;
5037450379
} else if (Z_TYPE_P(offset) == IS_RESOURCE) {
50380+
zend_use_resource_as_offset(offset);
5037550381
hval = Z_RES_HANDLE_P(offset);
5037650382
goto num_index_dim;
5037750383
} else if (IS_CV == IS_CV && Z_TYPE_P(offset) == IS_UNDEF) {

0 commit comments

Comments
 (0)