Bug #67582 [Opn]: Cloned SplObjectStorage with overwritten getHash fails offsetExists()

From: Date: Tue, 08 Jul 2014 05:03:35 +0000
Subject: Bug #67582 [Opn]: Cloned SplObjectStorage with overwritten getHash fails offsetExists()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186515@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: yohgaki@php.net Reported by: m dot drewek at smf dot de Summary: Cloned SplObjectStorage with overwritten getHash fails offsetExists() Status: Open Type: Bug Package: SPL related Operating System: Irrelevant PHP Version: 5.5.14 Block user comment: N Private report: N New Comment: http://3v4l.org/Kc9u1 It seems it's broken since 5.4.0. Previous Comments: ------------------------------------------------------------------------ [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 (#186515) next »