]> granicus.if.org Git - php/commitdiff
Fixed bug #40036 (empty() does not work correctly with ArrayObject when
authorIlia Alshanetsky <iliaa@php.net>
Sun, 7 Jan 2007 03:52:44 +0000 (03:52 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sun, 7 Jan 2007 03:52:44 +0000 (03:52 +0000)
using ARRAY_AS_PROPS).

NEWS
ext/spl/spl_array.c
ext/spl/tests/bug40036.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 917bb8af63babf8203b6470d0f44ba9d7ee028a5..bc1ab09422f826f023a1263e0751f11407eade2c 100644 (file)
--- 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)
 
index a4665d8e46aacbc48f6a530af015b88e5f2b1cd1..5ba4689490f21a62ae1fd983f1676817e6795b78 100755 (executable)
@@ -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 (file)
index 0000000..8569629
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Bug #40036 (empty() does not work correctly with ArrayObject when using ARRAY_AS_PROPS)
+--SKIPIF--
+<?php if (!extension_loaded("spl")) print "skip"; ?>
+--FILE--
+<?php
+class View extends ArrayObject
+{
+    public function __construct(array $array = array())
+    {
+        parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
+    }
+}
+
+$view = new View();
+$view->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===