php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48385 current() on SplObjectStorage returns boolean instead of object
Submitted: 2009-05-25 14:54 UTC Modified: 2009-05-26 07:24 UTC
From: karsten at typo3 dot org Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.3.0RC2 OS: *
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: karsten at typo3 dot org
New email:
PHP Version: OS:

 

 [2009-05-25 14:54 UTC] karsten at typo3 dot org
Description:
------------
When using current on an SplObjectStorage instance I'd expect (according 
to the documentation) to get the current object back. Instead I get back 
false.

Reproduce code:
---------------
<?php
$s = new SplObjectStorage();
$o = new stdClass();
$s->attach($o);
reset($s);
var_dump(current($s));
?>

Expected result:
----------------
object(stdClass)#2 (0) {
}


Actual result:
--------------
bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-25 17:06 UTC] colder@php.net
This is expected, current/reset/key... is supposed to work on arrays, and not on objects even if they implement the ArrayAccess interface.

Use $o->rewind(); $o->current(); ...
 [2009-05-26 07:24 UTC] karsten at typo3 dot org
Thanks for the hint. Although, this is not at all intuitive! Oh, well... 
:)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 14:01:37 2025 UTC