diff options
| -rw-r--r-- | ext/spl/spl_observer.c | 10 | ||||
| -rw-r--r-- | ext/spl/tests/bug67582.phpt | 24 |
2 files changed, 29 insertions, 5 deletions
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 40de5934d0..223e252e63 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -243,11 +243,6 @@ static zend_object *spl_object_storage_new_ex(zend_class_entry *class_type, zval intern->std.handlers = &spl_handler_SplObjectStorage; - if (orig) { - spl_SplObjectStorage *other = Z_SPLOBJSTORAGE_P(orig); - spl_object_storage_addall(intern, orig, other); - } - while (parent) { if (parent == spl_ce_SplObjectStorage) { if (class_type != spl_ce_SplObjectStorage) { @@ -262,6 +257,11 @@ static zend_object *spl_object_storage_new_ex(zend_class_entry *class_type, zval parent = parent->parent; } + if (orig) { + spl_SplObjectStorage *other = Z_SPLOBJSTORAGE_P(orig); + spl_object_storage_addall(intern, orig, other); + } + return &intern->std; } /* }}} */ diff --git a/ext/spl/tests/bug67582.phpt b/ext/spl/tests/bug67582.phpt new file mode 100644 index 0000000000..b22f615034 --- /dev/null +++ b/ext/spl/tests/bug67582.phpt @@ -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) |
