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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 + 30 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 11:01:29 2024 UTC