Skip to content

Commit ee864f8

Browse files
committed
Merge branch 'PHP-7.0'
2 parents d92c75f + 7ac24aa commit ee864f8

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

ext/spl/spl_array.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, zval *object, zval
276276
return &EG(error_zval);;
277277
}
278278

279+
try_again:
279280
switch (Z_TYPE_P(offset)) {
280281
case IS_NULL:
281282
offset_key = ZSTR_EMPTY_ALLOC();
@@ -355,6 +356,9 @@ static zval *spl_array_get_dimension_ptr(int check_inherited, zval *object, zval
355356
}
356357
}
357358
return retval;
359+
case IS_REFERENCE:
360+
ZVAL_DEREF(offset);
361+
goto try_again;
358362
default:
359363
zend_error(E_WARNING, "Illegal offset type");
360364
return (type == BP_VAR_W || type == BP_VAR_RW) ?
@@ -442,6 +446,8 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval
442446
if (Z_REFCOUNTED_P(value)) {
443447
Z_ADDREF_P(value);
444448
}
449+
450+
try_again:
445451
switch (Z_TYPE_P(offset)) {
446452
case IS_STRING:
447453
ht = spl_array_get_hash_table(intern, 0);
@@ -481,6 +487,9 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval
481487
}
482488
zend_hash_next_index_insert(ht, value);
483489
return;
490+
case IS_REFERENCE:
491+
ZVAL_DEREF(offset);
492+
goto try_again;
484493
default:
485494
zend_error(E_WARNING, "Illegal offset type");
486495
return;
@@ -603,7 +612,8 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
603612
if (!value) {
604613
HashTable *ht = spl_array_get_hash_table(intern, 0);
605614

606-
switch(Z_TYPE_P(offset)) {
615+
try_again:
616+
switch (Z_TYPE_P(offset)) {
607617
case IS_STRING:
608618
if ((tmp = zend_symtable_find(ht, Z_STR_P(offset))) != NULL) {
609619
if (check_empty == 2) {
@@ -637,7 +647,9 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
637647
return 0;
638648
}
639649
break;
640-
650+
case IS_REFERENCE:
651+
ZVAL_DEREF(offset);
652+
goto try_again;
641653
default:
642654
zend_error(E_WARNING, "Illegal offset type");
643655
return 0;

ext/spl/tests/bug71028.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #71028 (Undefined index with ArrayIterator)
3+
--FILE--
4+
<?php
5+
function cast(&$a) {
6+
$a = (int)$a;
7+
}
8+
9+
$a = new ArrayIterator;
10+
$a[-1] = 123;
11+
12+
$b = "-1";
13+
cast($b);
14+
15+
var_dump(isset($a[$b]));
16+
$a[$b] = "okey";
17+
echo $a[$b];
18+
?>
19+
--EXPECT--
20+
bool(true)
21+
okey

0 commit comments

Comments
 (0)