Fixed bug #61347 (inconsist isset behavior of Arrayobject)

This commit is contained in:
Xinchen Hui 2012-03-11 08:27:55 +00:00
parent 7bbf5fe650
commit a7639291b4
3 changed files with 77 additions and 39 deletions

1
NEWS
View file

@ -66,6 +66,7 @@ PHP NEWS
- SPL - SPL
. Fixed bug #61326 (ArrayObject comparison). (Gustavo) . Fixed bug #61326 (ArrayObject comparison). (Gustavo)
. Fixed bug #61347 (inconsist isset behavior of Arrayobject). (Laruence)
- SQLite3 extension: - SQLite3 extension:
. Add createCollation() method. (Brad Dewar) . Add createCollation() method. (Brad Dewar)

View file

@ -579,8 +579,9 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
switch(Z_TYPE_P(offset)) { switch(Z_TYPE_P(offset)) {
case IS_STRING: case IS_STRING:
if (check_empty) { {
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) { HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
if (zend_symtable_find(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &tmp) != FAILURE) {
switch (check_empty) { switch (check_empty) {
case 0: case 0:
return Z_TYPE_PP(tmp) != IS_NULL; return Z_TYPE_PP(tmp) != IS_NULL;
@ -591,20 +592,18 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
} }
} }
return 0; return 0;
} else {
return zend_symtable_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1);
} }
case IS_DOUBLE: case IS_DOUBLE:
case IS_RESOURCE: case IS_RESOURCE:
case IS_BOOL: case IS_BOOL:
case IS_LONG: case IS_LONG:
{
HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
if (offset->type == IS_DOUBLE) { if (offset->type == IS_DOUBLE) {
index = (long)Z_DVAL_P(offset); index = (long)Z_DVAL_P(offset);
} else { } else {
index = Z_LVAL_P(offset); index = Z_LVAL_P(offset);
} }
if (check_empty) {
HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) { if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) {
switch (check_empty) { switch (check_empty) {
case 0: case 0:
@ -616,8 +615,6 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o
} }
} }
return 0; return 0;
} else {
return zend_hash_index_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index);
} }
default: default:
zend_error(E_WARNING, "Illegal offset type"); zend_error(E_WARNING, "Illegal offset type");

View file

@ -0,0 +1,40 @@
--TEST--
Bug #61347 (inconsist isset behavior of Arrayobject)
--FILE--
<?php
$a = array('b' => NULL, 37 => NULL);
var_dump(isset($a['b'])); //false
$b = new ArrayObject($a);
var_dump(isset($b['b'])); //false
var_dump(isset($b[37])); //false
var_dump(isset($b['no_exists'])); //false
var_dump(empty($b['b'])); //true
var_dump(empty($b[37])); //true
var_dump(array_key_exists('b', $b)); //true
var_dump($b['b']);
$a = array('b' => '', 37 => false);
$b = new ArrayObject($a);
var_dump(isset($b['b'])); //true
var_dump(isset($b[37])); //true
var_dump(isset($b['no_exists'])); //false
var_dump(empty($b['b'])); //true
var_dump(empty($b[37])); //true
--EXPECT--
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
bool(true)
NULL
bool(true)
bool(true)
bool(false)
bool(true)
bool(true)