laruence Sun, 11 Mar 2012 08:27:55 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=324093
Log: Fixed bug #61347 (inconsist isset behavior of Arrayobject) Bug: https://bugs.php.net/61347 (Open) inconsist isset behavior of Arrayobject Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/spl/spl_array.c A php/php-src/branches/PHP_5_3/ext/spl/tests/bug61347.phpt U php/php-src/branches/PHP_5_4/NEWS U php/php-src/branches/PHP_5_4/ext/spl/spl_array.c A php/php-src/branches/PHP_5_4/ext/spl/tests/bug61347.phpt U php/php-src/trunk/ext/spl/spl_array.c A php/php-src/trunk/ext/spl/tests/bug61347.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2012-03-11 04:20:25 UTC (rev 324092) +++ php/php-src/branches/PHP_5_3/NEWS 2012-03-11 08:27:55 UTC (rev 324093) @@ -66,6 +66,7 @@ - SPL . Fixed bug #61326 (ArrayObject comparison). (Gustavo) + . Fixed bug #61347 (inconsist isset behavior of Arrayobject). (Laruence) - SQLite3 extension: . Add createCollation() method. (Brad Dewar) Modified: php/php-src/branches/PHP_5_3/ext/spl/spl_array.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/spl/spl_array.c 2012-03-11 04:20:25 UTC (rev 324092) +++ php/php-src/branches/PHP_5_3/ext/spl/spl_array.c 2012-03-11 08:27:55 UTC (rev 324093) @@ -578,49 +578,46 @@ } switch(Z_TYPE_P(offset)) { - 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) { - switch (check_empty) { - case 0: - return Z_TYPE_PP(tmp) != IS_NULL; - case 2: - return 1; - default: - return zend_is_true(*tmp); + case IS_STRING: + { + 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) { + case 0: + return Z_TYPE_PP(tmp) != IS_NULL; + case 2: + return 1; + default: + return zend_is_true(*tmp); + } } + 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_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - 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) { - switch (check_empty) { - case 0: - return Z_TYPE_PP(tmp) != IS_NULL; - case 2: - return 1; - default: - return zend_is_true(*tmp); + case IS_DOUBLE: + case IS_RESOURCE: + case IS_BOOL: + case IS_LONG: + { + HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (offset->type == IS_DOUBLE) { + index = (long)Z_DVAL_P(offset); + } else { + index = Z_LVAL_P(offset); } + if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) { + switch (check_empty) { + case 0: + return Z_TYPE_PP(tmp) != IS_NULL; + case 2: + return 1; + default: + return zend_is_true(*tmp); + } + } + return 0; } - return 0; - } else { - return zend_hash_index_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index); - } - default: - zend_error(E_WARNING, "Illegal offset type"); + default: + zend_error(E_WARNING, "Illegal offset type"); } return 0; } /* }}} */ Added: php/php-src/branches/PHP_5_3/ext/spl/tests/bug61347.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/spl/tests/bug61347.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/spl/tests/bug61347.phpt 2012-03-11 08:27:55 UTC (rev 324093) @@ -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) Modified: php/php-src/branches/PHP_5_4/NEWS =================================================================== --- php/php-src/branches/PHP_5_4/NEWS 2012-03-11 04:20:25 UTC (rev 324092) +++ php/php-src/branches/PHP_5_4/NEWS 2012-03-11 08:27:55 UTC (rev 324093) @@ -72,6 +72,9 @@ . Fixed bug #60968 (Late static binding doesn't work with ReflectionMethod::invokeArgs()). (Laruence) +- SPL: + . Fixed bug #61347 (inconsist isset behavior of Arrayobject). (Laruence) + - Standard: . Fixed memory leak in substr_replace. (Pierrick) . Make max_file_uploads ini directive settable outside of php.ini (Rasmus) Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_array.c =================================================================== --- php/php-src/branches/PHP_5_4/ext/spl/spl_array.c 2012-03-11 04:20:25 UTC (rev 324092) +++ php/php-src/branches/PHP_5_4/ext/spl/spl_array.c 2012-03-11 08:27:55 UTC (rev 324093) @@ -601,49 +601,46 @@ } switch(Z_TYPE_P(offset)) { - 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) { - switch (check_empty) { - case 0: - return Z_TYPE_PP(tmp) != IS_NULL; - case 2: - return 1; - default: - return zend_is_true(*tmp); + case IS_STRING: + { + 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) { + case 0: + return Z_TYPE_PP(tmp) != IS_NULL; + case 2: + return 1; + default: + return zend_is_true(*tmp); + } } } 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_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - 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) { - switch (check_empty) { - case 0: - return Z_TYPE_PP(tmp) != IS_NULL; - case 2: - return 1; - default: - return zend_is_true(*tmp); + case IS_DOUBLE: + case IS_RESOURCE: + case IS_BOOL: + case IS_LONG: + { + HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (offset->type == IS_DOUBLE) { + index = (long)Z_DVAL_P(offset); + } else { + index = Z_LVAL_P(offset); } + if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) { + switch (check_empty) { + case 0: + return Z_TYPE_PP(tmp) != IS_NULL; + case 2: + return 1; + default: + return zend_is_true(*tmp); + } + } + return 0; } - return 0; - } else { - return zend_hash_index_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index); - } - default: - zend_error(E_WARNING, "Illegal offset type"); + default: + zend_error(E_WARNING, "Illegal offset type"); } return 0; } /* }}} */ Added: php/php-src/branches/PHP_5_4/ext/spl/tests/bug61347.phpt =================================================================== --- php/php-src/branches/PHP_5_4/ext/spl/tests/bug61347.phpt (rev 0) +++ php/php-src/branches/PHP_5_4/ext/spl/tests/bug61347.phpt 2012-03-11 08:27:55 UTC (rev 324093) @@ -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) Modified: php/php-src/trunk/ext/spl/spl_array.c =================================================================== --- php/php-src/trunk/ext/spl/spl_array.c 2012-03-11 04:20:25 UTC (rev 324092) +++ php/php-src/trunk/ext/spl/spl_array.c 2012-03-11 08:27:55 UTC (rev 324093) @@ -601,49 +601,46 @@ } switch(Z_TYPE_P(offset)) { - 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) { - switch (check_empty) { - case 0: - return Z_TYPE_PP(tmp) != IS_NULL; - case 2: - return 1; - default: - return zend_is_true(*tmp); + case IS_STRING: + { + 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) { + case 0: + return Z_TYPE_PP(tmp) != IS_NULL; + case 2: + return 1; + default: + return zend_is_true(*tmp); + } } } 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_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - 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) { - switch (check_empty) { - case 0: - return Z_TYPE_PP(tmp) != IS_NULL; - case 2: - return 1; - default: - return zend_is_true(*tmp); + case IS_DOUBLE: + case IS_RESOURCE: + case IS_BOOL: + case IS_LONG: + { + HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (offset->type == IS_DOUBLE) { + index = (long)Z_DVAL_P(offset); + } else { + index = Z_LVAL_P(offset); } + if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE) { + switch (check_empty) { + case 0: + return Z_TYPE_PP(tmp) != IS_NULL; + case 2: + return 1; + default: + return zend_is_true(*tmp); + } + } + return 0; } - return 0; - } else { - return zend_hash_index_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index); - } - default: - zend_error(E_WARNING, "Illegal offset type"); + default: + zend_error(E_WARNING, "Illegal offset type"); } return 0; } /* }}} */ Added: php/php-src/trunk/ext/spl/tests/bug61347.phpt =================================================================== --- php/php-src/trunk/ext/spl/tests/bug61347.phpt (rev 0) +++ php/php-src/trunk/ext/spl/tests/bug61347.phpt 2012-03-11 08:27:55 UTC (rev 324093) @@ -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)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php