[英]Maximum function nesting level of '100' reached while testing my Guzzle client?
我對Guzzle內部的基本了解可能是導致此錯誤的原因(PHPUnit測試):
PHP致命錯誤:函數最大嵌套級別達到'100',正在中止! 在234行的\\ vendor \\ guzzle \\ guzzle \\ src \\ Guzzle \\ Http \\ QueryString.php中
似乎以下各節(插件和解析器)正在互相調用。 插件正在監聽command.before_send
事件,並添加一個閉包作為request.exception
事件的監聽器:
/**
* The plugin adds a closure listener for the event 'response.exception'. The
* closure is using the parser (RestInterfaceParser).
*/
class ResponseListener implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return array('command.before_send' => 'onCommandBeforeSend');
}
public function onCommandBeforeSend(Event $event)
{
// ...
$command = $event['command'];
$request = $command->getRequest();
$request->getEventDispatcher()->addListener(
'request.exception',
function (Event $event) use ($command, $parser) {
$parsed = $parser->parse($command);
// ...
}
);
}
}
到目前為止沒有什么特別的! 當我嘗試訪問響應對象時,該錯誤是由解析器引起的:
/**
* The parser invoked by the closure listener.
*/
class RestInterfaceParser implements ResponseParserInterface
{
public function parse(CommandInterface $command)
{
var_dump($command->getResponse());
}
}
刪除該行將消除錯誤。 但是,令人驚訝的是,我需要解析器內部的響應對象。 增加嵌套級別( xdebug.max_nesting_level = 1000
)無濟於事,因為這是“純”遞歸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.