ZF-8084: Segmentation Fault with Zend_Paginator_Adapter_Iterator + Zend_Cache
Description
If you use the iterator adapter and a serializing cache like the following you will crash php:
<?php
set_include_path('/tmp/zf/trunk/library/');
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$view = new Zend_View();
try {
$frontendOptions = array(
'caching' => true,
'lifetime' => 72000,
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => '/tmp/invite_vcfront' // Directory where to put the cache files
);
$cache = Zend_Cache::factory('Core','File', $frontendOptions,$backendOptions);
Zend_Paginator::setCache($cache);
$it = new ArrayIterator(array('test' => 'test', 'test2' => 'test2'));
$paginator = Zend_Paginator::factory($it);
$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber(1);
$paginator->setView($view);
// var_dump($paginator->getIterator());
foreach($paginator as $page){
echo var_dump($page)."\n";
}
} catch (Exception $e) {
echo $e;
}
echo "END\n";
First run (not cached)
php test.php string(4) "test" string(5) "test2" END
Second run (cached)
php test.php Segmentation fault
After cleaning cache this restarts on first run
The problem is that Zend_Paginator caches an instance of LimitIterator where is a bug in php: http://bugs.php.net/bug.php?id=49906
To solve this I created a new class Zend_Paginator_SerializableLimitIterator.
Comments
Posted by Marc Bennewitz (private) (mabe) on 2009-10-17T03:41:20.000+0000
added patch
Posted by Marc Bennewitz (private) (mabe) on 2009-10-22T14:23:17.000+0000
patch implemented in r18670 (added testcase Zend_Paginator_Adapter_IteratorTest::testGetItemsSerializable)
Posted by Carlos Buenosvinos (carlos.buenosvinos) on 2009-11-25T00:49:43.000+0000
"unserialize" DocBlock says "@paran". It should be "@param"