title: Maximum function nesting level of '100' reached while testing my Guzzle client?
body: <p>My very basic understanding of <a href="https://github.com/guzzle/guzzle" rel="nofollow">Guzzle</a> internals maybe the cause of this error (PHPUnit test):</p>
  
  <blockquote>
    <p>PHP Fatal error:  Maximum function nesting level of '100' reached,
    aborting! in
    \vendor\guzzle\guzzle\src\Guzzle\Http\QueryString.php
    on line 234</p>
  </blockquote>
  
  <p>It seems that the following sections (plugin and parser) are calling each other. The <strong>plugin</strong> is listening for <code>command.before_send</code> event, adding a closure as listener for the <code>request.exception</code> event:</p>
  
  <pre><code>/**
   * 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' =&gt; 'onCommandBeforeSend');
      }
  
      public function onCommandBeforeSend(Event $event)
      {
          // ...
          $command = $event['command'];
          $request = $command-&gt;getRequest();
  
          $request-&gt;getEventDispatcher()-&gt;addListener(
              'request.exception',
              function (Event $event) use ($command, $parser) {
                  $parsed = $parser-&gt;parse($command);
  
                  // ...
              }
          );
      }
  }
  </code></pre>
  
  <p>Nothing special so far! The error is caused by the <strong>parser</strong>, when I try to access the response object:</p>
  
  <pre><code>/**
   * The parser invoked by the closure listener.
   */
  class RestInterfaceParser implements ResponseParserInterface
  {
      public function parse(CommandInterface $command)
      {
          var_dump($command-&gt;getResponse());
      }
  }
  </code></pre>
  
  <p>Removing that line removes the error. But, big surprise, I need the response object inside the parser. Increasing the nesting level (<code>xdebug.max_nesting_level = 1000</code>) doesn't help because it's "pure" recursion here.</p>