Skip to content

Commit a763929

Browse files
committed
Fixed bug #61347 (inconsist isset behavior of Arrayobject)
1 parent 7bbf5fe commit a763929

File tree

3 files changed

+77
-39
lines changed

3 files changed

+77
-39
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ PHP NEWS
6666

6767
- SPL
6868
. Fixed bug #61326 (ArrayObject comparison). (Gustavo)
69+
. Fixed bug #61347 (inconsist isset behavior of Arrayobject). (Laruence)
6970

7071
- SQLite3 extension:
7172
. Add createCollation() method. (Brad Dewar)

ext/spl/spl_array.c

+36-39
Original file line numberDiff line numberDiff line change
@@ -578,49 +578,46 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
578578
}
579579

580580
switch(Z_TYPE_P(offset)) {
581-
case IS_STRING:
582-
if (check_empty) {
583-
if (zend_symtable_find(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &tmp) != FAILURE) {
584-
switch (check_empty) {
585-
case 0:
586-
return Z_TYPE_PP(tmp) != IS_NULL;
587-
case 2:
588-
return 1;
589-
default:
590-
return zend_is_true(*tmp);
581+
case IS_STRING:
582+
{
583+
HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
584+
if (zend_symtable_find(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &tmp) != FAILURE) {
585+
switch (check_empty) {
586+
case 0:
587+
return Z_TYPE_PP(tmp) != IS_NULL;
588+
case 2:
589+
return 1;
590+
default:
591+
return zend_is_true(*tmp);
592+
}
591593
}
594+
return 0;
592595
}
593-
return 0;
594-
} else {
595-
return zend_symtable_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1);
596-
}
597-
case IS_DOUBLE:
598-
case IS_RESOURCE:
599-
case IS_BOOL:
600-
case IS_LONG:
601-
if (offset->type == IS_DOUBLE) {
602-
index = (long)Z_DVAL_P(offset);
603-
} else {
604-
index = Z_LVAL_P(offset);
605-
}
606-
if (check_empty) {
607-
HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
608-
if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) {
609-
switch (check_empty) {
610-
case 0:
611-
return Z_TYPE_PP(tmp) != IS_NULL;
612-
case 2:
613-
return 1;
614-
default:
615-
return zend_is_true(*tmp);
596+
case IS_DOUBLE:
597+
case IS_RESOURCE:
598+
case IS_BOOL:
599+
case IS_LONG:
600+
{
601+
HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
602+
if (offset->type == IS_DOUBLE) {
603+
index = (long)Z_DVAL_P(offset);
604+
} else {
605+
index = Z_LVAL_P(offset);
606+
}
607+
if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) {
608+
switch (check_empty) {
609+
case 0:
610+
return Z_TYPE_PP(tmp) != IS_NULL;
611+
case 2:
612+
return 1;
613+
default:
614+
return zend_is_true(*tmp);
615+
}
616616
}
617+
return 0;
617618
}
618-
return 0;
619-
} else {
620-
return zend_hash_index_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index);
621-
}
622-
default:
623-
zend_error(E_WARNING, "Illegal offset type");
619+
default:
620+
zend_error(E_WARNING, "Illegal offset type");
624621
}
625622
return 0;
626623
} /* }}} */

ext/spl/tests/bug61347.phpt

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #61347 (inconsist isset behavior of Arrayobject)
3+
--FILE--
4+
<?php
5+
$a = array('b' => NULL, 37 => NULL);
6+
var_dump(isset($a['b'])); //false
7+
8+
$b = new ArrayObject($a);
9+
var_dump(isset($b['b'])); //false
10+
var_dump(isset($b[37])); //false
11+
var_dump(isset($b['no_exists'])); //false
12+
var_dump(empty($b['b'])); //true
13+
var_dump(empty($b[37])); //true
14+
15+
var_dump(array_key_exists('b', $b)); //true
16+
var_dump($b['b']);
17+
18+
$a = array('b' => '', 37 => false);
19+
$b = new ArrayObject($a);
20+
var_dump(isset($b['b'])); //true
21+
var_dump(isset($b[37])); //true
22+
var_dump(isset($b['no_exists'])); //false
23+
var_dump(empty($b['b'])); //true
24+
var_dump(empty($b[37])); //true
25+
26+
27+
--EXPECT--
28+
bool(false)
29+
bool(false)
30+
bool(false)
31+
bool(false)
32+
bool(true)
33+
bool(true)
34+
bool(true)
35+
NULL
36+
bool(true)
37+
bool(true)
38+
bool(false)
39+
bool(true)
40+
bool(true)

0 commit comments

Comments
 (0)