php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49906 LimitIterator doesn't work with un-/serialize
Submitted: 2009-10-16 23:59 UTC Modified: 2016-06-07 17:17 UTC
Votes:11
Avg. Score:4.5 ± 0.8
Reproduced:9 of 9 (100.0%)
Same Version:4 (44.4%)
Same OS:7 (77.8%)
From: marc-bennewitz at arcor dot de Assigned: colder
Status: Assigned Package: SPL related
PHP Version: 5.3SVN-2009-10-16 (snap) OS: Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-10-16 23:59 UTC] marc-bennewitz at arcor dot de
Description:
------------
Serializing of LimitIterator doesn't work.


Reproduce code:
---------------
$it = new ArrayIterator(array('test' => 'test'));

$limitit = new LimitIterator($it, 0, 10);
var_dump($limitit);
var_dump($limitit->getInnerIterator());

$limititSer = serialize($limitit);
var_dump($limititSer);

$limitit = unserialize($limititSer);
var_dump($limitit);
var_dump($limitit->getInnerIterator());

Expected result:
----------------
object(LimitIterator)#2 (0) {
  /* some content */
}
object(ArrayIterator)#1 (1) {
  ["storage":"ArrayIterator":private]=>
  array(1) {
    ["test"]=>
    string(4) "test"
  }
}
string(25) "O:13:"LimitIterator":0:{...........}"
object(LimitIterator)#3 (0) {
  /* some content */
}
object(ArrayIterator)#1 (1) {
  ["storage":"ArrayIterator":private]=>
  array(1) {
    ["test"]=>
    string(4) "test"
  }
}

Actual result:
--------------
object(LimitIterator)#2 (0) {
}
object(ArrayIterator)#1 (1) {
  ["storage":"ArrayIterator":private]=>
  array(1) {
    ["test"]=>
    string(4) "test"
  }
}
string(25) "O:13:"LimitIterator":0:{}"
object(LimitIterator)#3 (0) {
}
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-17 00:12 UTC] marek at flaber dot net
When you actually trying to rewind the object it is making php to 
segfault.

Like here:

$limitit = unserialize( serialize($limitit) );
echo $limitit->next();
var_dump($limitit->getInnerIterator());
 [2016-06-07 17:17 UTC] cmb@php.net
FWIW: as of PHP 5.3.7 there is an error thrown when
$limitit->getInnerIterator() is called[1]:

| Fatal error: Uncaught exception 'LogicException' with message
| 'The object is in an invalid state as the parent constructor was
| not called' in …

[1] <https://3v4l.org/9aOX8>
 
PHP Copyright © 2001-2016 The PHP Group
All rights reserved.
Last updated: Thu Aug 25 13:01:40 2016 UTC