Sending “var_dump” to FireBug console

前端 未结 12 1409
忘掉有多难
忘掉有多难 2020-12-31 13:11

As you know var_dump() in addition to value show its data type and length.

Is there any way to log its output to

12条回答
  •  星月不相逢
    2020-12-31 13:27

    I always use this script in combination with Zend_Log_Writer_Firebug (using firephp http://www.firephp.org/), because after redirects in the applicaton or ajax requests debugging with xdebug does not always work as expected:

    require_once '/Zend/Log.php';
    require_once '/Zend/Log/Writer/Firebug.php';  
    require_once '/Zend/Controller/Response/Http.php';
    require_once '/Zend/Controller/Request/Http.php';
    
    // create the logger and log writer
    $writer = new Zend_Log_Writer_Firebug();
    $logger = new Zend_Log($writer);
    
    // get the wildfire channel
    $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
    
    // create and set the HTTP response
    $response = new Zend_Controller_Response_Http();
    $channel->setResponse($response);
    
    // create and set the HTTP request
    $channel->setRequest(new Zend_Controller_Request_Http());
    
    // record log messages
    $logger->info('test');
    $logger->info(var_export($_SESSION,true));
    $logger->info(count(var_export($_SESSION,true)));
    $logger->info(strlen(var_export('hello',true)));
    $logger->info(get_type($_SESSION,true));  
    
    // insert the wildfire headers into the HTTP response
    $channel->flush();
    
    // send the HTTP response headers
    $response->sendHeaders();
    

    You can build your own library to get the type of a variable:

    
    

    Using a function call to var_dump_ret as argument for $logger->info() might be helpful, too. I haven't tested it yet.

    function var_dump_ret($mixed = null) {
      ob_start();
      var_dump($mixed);
      $content = ob_get_contents();
      ob_end_clean();
      return $content;
    }
    

提交回复
热议问题