Bug #67582 [Ver->Csd]: Cloned SplObjectStorage with overwritten getHash fails offsetExists()

From: Date: Sun, 20 Mar 2016 16:49:02 +0000
Subject: Bug #67582 [Ver->Csd]: Cloned SplObjectStorage with overwritten getHash fails offsetExists()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199965@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67582&edit=1 ID: 67582 Updated by: nikic@php.net Reported by: m dot drewek at smf dot de Summary: Cloned SplObjectStorage with overwritten getHash fails offsetExists() -Status: Verified +Status: Closed Type: Bug Package: SPL related Operating System: Irrelevant PHP Version: 5.5.14 Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikic Revision: http://git.php.net/?p=php-src.git;a=commit;h=cc3cdd00578006a5684e6dfaf81532a13326b9fe Log: Fixed bug #67582 Previous Comments: ------------------------------------------------------------------------ [2015-07-08 12:12:18] nospampls at example dot org it is broken since 5.4 because getHash() was introduced since php 5.4 fix this please! ------------------------------------------------------------------------ [2014-07-08 05:03:34] yohgaki@php.net http://3v4l.org/Kc9u1 It seems it's broken since 5.4.0. ------------------------------------------------------------------------ [2014-07-07 09:39:10] m dot drewek at smf dot de Description: ------------ We use SplObjectStorage to store Entities, but overwrite getHash() to prevent storing multiple objects with logically the same Entity (so "new Entity(5)" should be considered equal to another "new Entity(5)"). This works fine. Now we considered that cloning such a list will make the offsetExists() method fail, as the test script shows. As a consequence, removeAll() will not remove anything, filter() will not filter anything, sort() will just double the number of items contained, etc. Test script: --------------- 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(); // No issues if using "new SplObjectStorage()" $list->attach(new TestObject()); foreach($list as $x) var_dump($list->offsetExists($x)); // TRUE $list2 = clone $list; foreach($list2 as $x) var_dump($list2->offsetExists($x)); // FALSE Expected result: ---------------- Both the cloned and the original list return TRUE when calling offsetExists() on a contained object. Actual result: -------------- Only the original list contains TRUE, while the cloned one returns FALSE. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67582&edit=1

« previous php.bugs (#199965) next »