Use Firebug and FirePHP to Debug PHP

Source: Internet
Author: User
Using Firebug and FirePHP to Debug PHP, if you are the same as me, you will not be able to leave FireBug when developing web projects. This small "bug" is a magical and useful HTML/CSS/JavaScript/Ajax debugger. But you may not know that this can also be used to debug PHP. Yes, it can. thanks to a Fire named FirePHP for using Firebug and FirePHP to Debug PHP.
If you are the same as me, you will not be able to leave FireBug when developing web projects. This small "bug" is a magical and useful HTML/CSS/JavaScript/Ajax debugger. But you may not know that this can also be used to debug PHP. Yes, it can. thanks to a FireFox plug-in named FirePHP.

Through a small server Library and the plug-in on Firebug, your PHP script can send debugging information to the browser and easily use the corresponding HTTP header encoding. Once set, you can get PHP script warnings and errors in the Fiirebug console, just like directly debugging JavaScript.
To use this tool, you must first install the FirePHP plug-in. You must have installed FireBug for this plug-in. After installing FirePHP, when you re-open the Firebug panel, you will see a new blue bug icon. Click this icon to display a menu to enable or disable FirePHP.



Of course, at this time we can not do anything, you also need to install FirePHP server, click here to download (http://www.firephp.org/HQ/Install.htm ). This is an independent version. you can download it manually or use PEAR. After installation, 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 moment, we will focus on independent functions.

Once you deploy the FirePHP library on your server, you also need to add the following code to your code:

Require_once ('firephpcore/fb. php ');
This is because FirePHP sends recorded data through the HTTP header. you need to cache the output generated by your code to respond to the header information and obtain the content generated by the code from here. This can be achieved through the ob_start in the code header.
Ob_start ();
After these steps are completed, you can start using FirePHP. All you need to do is call the fb function wherever 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 );
The code will be output in the Firebug console as follows:



You can also use FirePHP to track the execution of your program. by using FirePHP: TRACE constant, you can view the number of rows, class names, and method names in the places where fb is called.

1 function hello (){
2 fb ('Hello World! ', FirePHP: TRACE );
3}
4 function greet (){
5 hello ();
6}
7 greet ();
The output is as follows:



This tracking function can perfectly debug more complex code, allowing you to precisely know where your method is called.
Of course, don't forget to remove your debugging statement before your code is released.
There is still a lot of FirePHP content not involved here. I just want to show you the FirePHP API and many advanced object-oriented APIs. You can get more related content on the FirePHP site. remember to read it ~

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.