Firefox plugin firephp debug php

Source: Internet
Author: User
Tags array php script

Author: Louis Simoneau
Original link:http://www.sitepoint.com/blogs/2010/02/09/debug-php-firebug-firephp

Translator:ALSWL


If you are like me, you will not be able to leave FireBugwhen you develop Web projects. This small "bug" is a magical and useful Html/css/javascript/ajax debugger. But you may not know this can also be used to debug PHP, yes, it can, thanks to a firephp called Firefox plug-ins.

With a small server library, and the plugin on the Firebug, your PHP script can send debugging information to the browser, easily encoded via HTTP headers. Once you've set up, you can get PHP script warnings and errors in the Fiirebug console, and it feels like debugging JavaScript directly

To use this tool, first you need to install the firephp plugin . This plugin requires you to have the Firebug installed. After installing the firephp, reopen the Firebug panel and you'll see a new blue bug icon. Clicking on this icon will show a menu that turns firephp on or off.

Of course, at this time we can not do anything, you also need to install the firephp server, click here to download. This is a standalone version that you can download manually or use pear. After the installation, you can easily add this library to your code. It has been designed in many versions to integrate into multiple frameworks or management systems, such as wp-firephp plugin for WordPress and jfirephp plugin for Joomla. Regardless of these, we will focus on the independent function.

Once you have deployed the Firephp library on your server, you will also need to add the following code to your code:

require_once("FirePHPCore/fb.php");

This is because firephp sends record data through HTTP hair, you need to cache the output generated by your code to respond to header information from here to get the code generated content. This can be done by the head of the code ob_start .

ob_start();

When these steps are complete, you can start using firephp. All you need to do is call the fb function where you want to record it. You can also use an optional label and constant to define predefined information, an error, a warning, or a message.

$var = Array ("A" => "pizza", "B" => "cookies", "C" => "celery");
FB ($var);
FB ($var, "an array");
FB ($var, Firephp::warn);
FB ($var, firephp::info);
FB ($var, "an array with an Error type", firephp::error);
$var = array("a"=>"pizza", "b"=>"cookies", "c"=>"celery");fb($var);fb($var, "An array");fb($var, FirePHP::WARN);fb($var, FirePHP::INFO);fb($var, "An array with an Error type", FirePHP::ERROR);

The code will be output in the Firebug console as shown below

You can also use firephp to track the execution of your program: by using FirePHP::TRACE常量,你可以在fb被调用的地方查看行数、类名和方法名

1 function  Hello ()  { 
  FB ("hello world!",  firephp::trace);  
3 } 
4 function greet ()  { 
5   hello ();  
6 } 
7 greet ();  
function hello() { fb("Hello World!", FirePHP::TRACE);}function greet() { hello();}greet();

The resulting output is as follows

This tracking feature is perfect for debugging more complex code, letting you know exactly where your method is being invoked.

Of course, don't forget that you need to remove your debug statements before your code is released.

There are still a lot of firephp content that is not covered. I'm just showing you the firephp API and a lot of advanced object-oriented APIs. You can get more relevant content in firephp site, remember to look at it oh ~

"Disclaimer: This translation is only for the purpose of foreign language learning, the original author's personal views and the translator and translation network is irrelevant."



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.