|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63678 SplObjectStorage->current() !== current(SplObjectStorage)
Submitted: 2012-12-03 21:07 UTC Modified: 2012-12-09 01:46 UTC
From: Alex at phpguide dot co dot il Assigned:
Status: Duplicate Package: SPL related
PHP Version: 5.4.9 OS: debian 6
Private report: No CVE-ID: None
 [2012-12-03 21:07 UTC] Alex at phpguide dot co dot il
$SplObjectStorage->current() returns different value from

Test script:
class test
	public $val;
	public function __construct()
		$this->val = rand();

class blat extends \SplObjectStorage
	public function add()
		$this->attach(new test());

$blat = new blat();

var_dump($blat->current() === current($blat));
// null === false

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-04 00:25 UTC] mail+php at requinix dot net
SplObjectStorage provides ->current() as part of the implementation to 
Iterator/Traversable. If you want to call it directly you may need to obey the 
Iterator convention of calling ->rewind() first.

But doing so only changes the ->current() value to be the object and not null. 
Even with $blat->rewind() and reset($blat) both key() and current() behave 
differently. In the example for SplObjectStorage::current() it includes

$object = $s->current(); // similar to current($s)

so I would also expect them to behave the same.

tl;dr with ->rewind() and reset():
key($blat)==null, current($blat)==false
$blat->key()==0, $blat->current()==a test object

Without ->rewind() and reset():
key($blat)==null, current($blat)==false
$blat->key()==0, $blat->current()==null
 [2012-12-09 01:46 UTC]
-Status: Open +Status: Duplicate
 [2012-12-09 01:46 UTC]
This is a duplicate of #49369 (
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC