簡體   English   中英

Session\\Container 定義上的 Zf2“迭代器類不存在”

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

有時在我的網站 (ZendFramework2) 上,設置會話變量時會出錯。 錯誤:

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

代碼 Module.php 第 97 行:

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

我嘗試,但我找不到原因。 你有什么主意嗎? 需要更多信息? 謝謝你。

這是 ArrayObject/PhpReferenceCompatibility 中的 setIteratorClass 方法傳遞空 $class 參數的結果。 我不確定為什么它有時會得到一個空值,但我在我的情況下修復它的方法是在傳遞空對象時將迭代器類設置為“ArrayIterator”,如下所示:

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

在最新的 zf2 版本中, ArrayObject/PhpReferenceCompatibility類已被刪除,因此請在stdlib/ArrayObject.php進行更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM