|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: Alex at phpguide dot co dot il
New email:
PHP Version: OS:


 [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-2023 The PHP Group
All rights reserved.
Last updated: Fri Jun 09 11:03:41 2023 UTC