简体   繁体   中英

Zf2 "The iterator class does not exist" on Session\Container definition

Sometimes on my website (ZendFramework2), I get an error when setting a session variable. The error:

PHP Fatal error:  Uncaught exception 'Zend\\Stdlib\\Exception\\InvalidArgumentException' with message 'The iterator class does not exist' in /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php:374
Stack trace:
#0 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php(414): Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->setIteratorClass(NULL)
#1 [internal function]: Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->unserialize('a:4:{s:7:"stora...')
#2 /MySite/vendor/zendframework/zendframework/library/Zend/Session/SessionManager.php(95): session_start()
#3 /MySite/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\\Session\\SessionManager->start()
#4 /MySite/module/Application/Module.php(97): Zend\\Session\\AbstractContainer->__construct('site')
#5 [internal function]: Application\\Module->onBootstrap(Object(Zend\\Mvc\\MvcEvent))
#6 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php on line 374

Code Module.php line 97 :

$s_site = new \Zend\Session\Container('site');

I try but I can not find why. Do you have any idea? Need more informations? Thank you.

The is a result of the setIteratorClass method in ArrayObject/PhpReferenceCompatibility being passed a null $class argument. I'm not sure why it sometimes gets a null, but the way I fixed it in my case was to set the iterator class as 'ArrayIterator' when passed a null object, like this:

if (!isset($class)) {
    $class = 'ArrayIterator';
}

在最新的 zf2 版本中, ArrayObject/PhpReferenceCompatibility类已被删除,因此请在stdlib/ArrayObject.php进行更改。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM