From: Ilia Alshanetsky Date: Sun, 7 Jan 2007 03:52:44 +0000 (+0000) Subject: Fixed bug #40036 (empty() does not work correctly with ArrayObject when X-Git-Tag: php-5.2.1RC3~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5068511748861c9dbeb603ec704f07bf81959901;p=php Fixed bug #40036 (empty() does not work correctly with ArrayObject when using ARRAY_AS_PROPS). --- diff --git a/NEWS b/NEWS index 917bb8af63..bc1ab09422 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ PHP NEWS ?? Jan 2007, PHP 5.2.1RC3 - Improved proc_open(). Now on Windows it can run external commands not through CMD.EXE. (Dmitry) +- Fixed bug #40036 (empty() does not work correctly with ArrayObject when using + ARRAY_AS_PROPS). (Ilia) - Fixed bug #39504 (xmlwriter_write_dtd_entity() creates Attlist tag, not entity). (Hannes) diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index a4665d8e46..5ba4689490 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -476,7 +476,16 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o switch(Z_TYPE_P(offset)) { case IS_STRING: - return zend_symtable_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1); + if (check_empty) { + zval **tmp; + HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (zend_hash_find(ht, Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &tmp) != FAILURE && zend_is_true(*tmp)) { + return 1; + } + 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: @@ -486,7 +495,16 @@ static int spl_array_has_dimension_ex(int check_inherited, zval *object, zval *o } else { index = Z_LVAL_P(offset); } - return zend_hash_index_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index); + if (check_empty) { + zval **tmp; + HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + if (zend_hash_index_find(ht, index, (void **)&tmp) != FAILURE && zend_is_true(*tmp)) { + return 1; + } + 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"); } diff --git a/ext/spl/tests/bug40036.phpt b/ext/spl/tests/bug40036.phpt new file mode 100644 index 0000000000..8569629d36 --- /dev/null +++ b/ext/spl/tests/bug40036.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #40036 (empty() does not work correctly with ArrayObject when using ARRAY_AS_PROPS) +--SKIPIF-- + +--FILE-- +foo = false; +$view->bar = null; +$view->baz = ''; +if (empty($view['foo']) || empty($view->foo)) { + echo "View::foo empty\n"; +} +if (empty($view['bar']) || empty($view->bar)) { + echo "View::bar empty\n"; +} +if (empty($view['baz']) || empty($view->baz)) { + echo "View::baz empty\n"; +} +?> +===DONE=== +--EXPECT-- +View::foo empty +View::bar empty +View::baz empty +===DONE===