]> granicus.if.org Git - php/commitdiff
- Fixed bug #61326 (ArrayObject comparison).
authorGustavo André dos Santos Lopes <cataphract@php.net>
Sat, 10 Mar 2012 17:19:39 +0000 (17:19 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Sat, 10 Mar 2012 17:19:39 +0000 (17:19 +0000)
NEWS
ext/spl/spl_array.c
ext/spl/tests/bug61326.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 9503ce01b3b773b0e282731386eeedcd5fc3c949..24957f09fe4eb841dfc5465e898a30cbe4870ff0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -47,6 +47,9 @@ PHP                                                                        NEWS
   . Fixed bug #61267 (pdo_pgsql's PDO::exec() returns the number of SELECTed
     rows on postgresql >= 9). (ben dot pineau at gmail dot com)
 
+- PDO_Sqlite extension:
+  . Add createCollation support. (Damien)
+
 - Phar:
   . Fixed bug #61184 (Phar::webPhar() generates headers with trailing NUL
     bytes). (Nikic)
@@ -60,13 +63,13 @@ PHP                                                                        NEWS
     chunksize length line is > 10 bytes). (Ilia)
   . Fixed bug #60887 (SoapClient ignores user_agent option and sends no
     User-Agent header). (carloschilazo at gmail dot com)
-    
+
+- SPL
+  . Fixed bug #61326 (ArrayObject comparison). (Gustavo)
+
 - SQLite3 extension:
   . Add createCollation() method. (Brad Dewar)
 
-- PDO_Sqlite extension:
-  . Add createCollation support. (Damien)
-
 - Reflection:
   . Fixed bug #60968 (Late static binding doesn't work with 
     ReflectionMethod::invokeArgs()). (Laruence)
index 434fa174e700c39df063d9bde027dc31f55376f9..be92918225d2b64027ed2dd637f79b8416b856a5 100755 (executable)
@@ -836,6 +836,30 @@ static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{
        std_object_handlers.unset_property(object, member TSRMLS_CC);
 } /* }}} */
 
+static int spl_array_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
+{
+       HashTable                       *ht1,
+                                               *ht2;
+       spl_array_object        *intern1,
+                                               *intern2;
+       int                                     result  = 0;
+       zval                            temp_zv;
+
+       intern1 = (spl_array_object*)zend_object_store_get_object(o1 TSRMLS_CC);
+       intern2 = (spl_array_object*)zend_object_store_get_object(o2 TSRMLS_CC);
+       ht1             = spl_array_get_hash_table(intern1, 0 TSRMLS_CC);
+       ht2             = spl_array_get_hash_table(intern2, 0 TSRMLS_CC);
+
+       zend_compare_symbol_tables(&temp_zv, ht1, ht2 TSRMLS_CC);
+       result = (int)Z_LVAL(temp_zv);
+       /* if we just compared std.properties, don't do it again */
+       if (result == 0 &&
+                       !(ht1 == intern1->std.properties && ht2 == intern2->std.properties)) {
+               result = std_object_handlers.compare_objects(o1, o2 TSRMLS_CC);
+       }
+       return result;
+} /* }}} */
+
 static int spl_array_skip_protected(spl_array_object *intern, HashTable *aht TSRMLS_DC) /* {{{ */
 {
        char *string_key;
@@ -2003,6 +2027,8 @@ PHP_MINIT_FUNCTION(spl_array)
        spl_handler_ArrayObject.has_property = spl_array_has_property;
        spl_handler_ArrayObject.unset_property = spl_array_unset_property;
 
+       spl_handler_ArrayObject.compare_objects = spl_array_compare_objects;
+
        REGISTER_SPL_STD_CLASS_EX(ArrayIterator, spl_array_object_new, spl_funcs_ArrayIterator);
        REGISTER_SPL_IMPLEMENTS(ArrayIterator, Iterator);
        REGISTER_SPL_IMPLEMENTS(ArrayIterator, ArrayAccess);
diff --git a/ext/spl/tests/bug61326.phpt b/ext/spl/tests/bug61326.phpt
new file mode 100644 (file)
index 0000000..85b5779
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #61326: ArrayObject comparison
+--FILE--
+<?php
+$aobj1 = new ArrayObject(array(0));
+$aobj2 = new ArrayObject(array(1));
+var_dump($aobj1 == $aobj2);
+
+$aobj3 = new ArrayObject(array(0));
+var_dump($aobj1 == $aobj3);
+
+$aobj3->foo = 'bar';
+var_dump($aobj1 == $aobj3);
+--EXPECT--
+bool(false)
+bool(true)
+bool(false)