Bug #63678 [Opn->Dup]: SplObjectStorage->current() !== current(SplObjectStorage)
Edit report at https://bugs.php.net/bug.php?id=63678&edit=1
ID: 63678
Updated by: levim@php.net
Reported by: Alex at phpguide dot co dot il
Summary: SplObjectStorage->current() !==
current(SplObjectStorage)
-Status: Open
+Status: Duplicate
Type: Bug
Package: SPL related
Operating System: debian 6
PHP Version: 5.4.9
Block user comment: N
Private report: N
New Comment:
This is a duplicate of #49369 (https://bugs.php.net/bug.php?id=49369).
Previous Comments:
------------------------------------------------------------------------
[2012-12-04 00:25:55] 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-03 21:07:18] Alex at phpguide dot co dot il
Description:
------------
$SplObjectStorage->current() returns different value from
current($SplObjectStorage).
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();
$blat->add();
$blat->add();
$blat->add();
$blat->add();
var_dump($blat->current() === current($blat));
// null === false
Expected result:
----------------
true
Actual result:
--------------
false
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63678&edit=1
Thread (3 messages)