diff options
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | ext/spl/spl_observer.c | 10 | ||||
| -rw-r--r-- | ext/spl/tests/bug67582.phpt | 24 |
3 files changed, 33 insertions, 5 deletions
@@ -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) diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 08cf66a67b..fb0b29fccd 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -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 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) |
