]> granicus.if.org Git - php/commitdiff
Fixed bug #67582
authorNikita Popov <nikic@php.net>
Sun, 20 Mar 2016 16:46:12 +0000 (17:46 +0100)
committerNikita Popov <nikic@php.net>
Sun, 20 Mar 2016 16:46:12 +0000 (17:46 +0100)
NEWS
ext/spl/spl_observer.c
ext/spl/tests/bug67582.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index c2cca344e1bac1e311e3e3ac21faee087e30082f..cf7edaf931cd9a12c81b5c52171c9f1f7a9fbd0f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,10 @@ PHP                                                                        NEWS
   . Fixed bug #71820 (pg_fetch_object binds parameters before
     call constructor). (Anatol)
 
+- SPL:
+  . Fixed bug #67582 (Cloned SplObjectStorage with overwritten getHash fails
+    offsetExists()). (Nikita)
+
 - Standard:
   . Fixed bug #71840 (Unserialize accepts wrongly data). (Ryat, Laruence)
 
index 08cf66a67b8fb7bace4f1dcab13d2f3749c4c448..fb0b29fccd5b48d0f5f47db7f38948e6b411fd09 100644 (file)
@@ -275,11 +275,6 @@ static zend_object_value spl_object_storage_new_ex(zend_class_entry *class_type,
        retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_SplOjectStorage_free_storage, NULL TSRMLS_CC);
        retval.handlers = &spl_handler_SplObjectStorage;
 
-       if (orig) {
-               spl_SplObjectStorage *other = (spl_SplObjectStorage*)zend_object_store_get_object(orig TSRMLS_CC);
-               spl_object_storage_addall(intern, orig, other TSRMLS_CC);
-       }
-
        while (parent) {
                if (parent == spl_ce_SplObjectStorage) {
                        if (class_type != spl_ce_SplObjectStorage) {
@@ -294,6 +289,11 @@ static zend_object_value spl_object_storage_new_ex(zend_class_entry *class_type,
                parent = parent->parent;
        }
 
+       if (orig) {
+               spl_SplObjectStorage *other = (spl_SplObjectStorage*)zend_object_store_get_object(orig TSRMLS_CC);
+               spl_object_storage_addall(intern, orig, other TSRMLS_CC);
+       }
+
        return retval;
 }
 /* }}} */
diff --git a/ext/spl/tests/bug67582.phpt b/ext/spl/tests/bug67582.phpt
new file mode 100644 (file)
index 0000000..b22f615
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #67582: Cloned SplObjectStorage with overwritten getHash fails offsetExists()
+--FILE--
+<?php
+
+class MyObjectStorage extends SplObjectStorage {
+       // Overwrite getHash() with just some (working) test-method
+       public function getHash($object) { return get_class($object); }
+}
+
+class TestObject {}
+
+$list = new MyObjectStorage();
+$list->attach(new TestObject());
+
+foreach($list as $x) var_dump($list->offsetExists($x));
+
+$list2 = clone $list;
+foreach($list2 as $x) var_dump($list2->offsetExists($x));
+
+?>
+--EXPECT--
+bool(true)
+bool(true)