Apply Firebug and firephp to debug PHP

Source: Internet
Author: User
Debug PHP with Firebug and firephp
If you are like me, you will not be able to leave Firebug at all when developing 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 Firefox plugin called firephp.

Through a small service-side library, and this plugin on the firebug, your PHP script can send debugging information to the browser, easily encoded by the corresponding HTTP header. Once you've set up, you can get PHP script warnings and errors in the Fiirebug console, just like you would debug JavaScript directly
With this tool, you first need to install the firephp plugin. This plugin requires that you have installed Firebug. Once you've installed the firephp, reopen the Firebug panel and you'll see a new blue bug icon added. Clicking on this icon will cause a menu to open or close the firephp.



Of course, we can not do anything at this time, you also need to install Firephp server, click here to download (http://www.firephp.org/HQ/Install.htm). This is a standalone version that you can download manually or use pear. After loading, you can easily add this library to your code. It has been designed with many versions to integrate into multiple frameworks or management systems, such as wp-firephp plugin for WordPress and jfirephp plugin for Joomla. For the time being, we will focus on independent functions.

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

Require_once (' firephpcore/fb.php ');
This is because firephp sends the recorded data through the HTTP hair, you need to cache the output generated by your code in order to respond to the header information from here to get the content generated by the code. This can be done in the ob_start of the code head.
Ob_start ();
When these steps are complete, you can start using firephp. All you need to do is call the FB function in any place you want to record. You can also use an optional tag and constant to define predefined information, an error, a warning, or a piece of information.

$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);
These codes will be shown in the Firebug console output as follows



You can also use firephp to track the execution of your program: by using the Firephp::trace constant, you can view the number of rows, class names, and method names where FB is called

1function Hello () {
2 fb (' Hello world! ', firephp::trace);
3}
4function greet () {
5 Hello ();
6}
7greet ();
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 called.
Of course, don't forget that you need to remove your debug statements before your code is released.
There are a lot of firephp that are not involved. I'm just showing you the firephp API and many advanced object-oriented APIs. You can get more relevant content at firephp site, remember to look at it oh ~
  • Related Article

    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.