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
 [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: Sat May 11 01:01:31 2024 UTC