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

From: Date: Wed, 08 Jul 2015 12:12:20 +0000
Subject: Bug #67582 [Com]: Cloned SplObjectStorage with overwritten getHash fails offsetExists()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194206@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 Comment by: nospampls at example dot org Reported by: m dot drewek at smf dot de Summary: Cloned SplObjectStorage with overwritten getHash fails offsetExists() Status: Verified Type: Bug Package: SPL related Operating System: Irrelevant PHP Version: 5.5.14 Block user comment: N Private report: N New Comment: it is broken since 5.4 because getHash() was introduced since php 5.4 fix this please! Previous Comments: ------------------------------------------------------------------------ [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 (#194206) next »