Use the FireFox plug-in 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 HTMLCSSJavaScriptAjax debugger. However, if you are like me, you will be unable to leave when developing web projects. FireBug. 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 installFirePHP 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, we cannot do anything at this time. you still need to install the FirePHP server. 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, suchWP-FirePHP plugin for WordPressAndJFirePHP 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 done throughob_start
.
ob_start();
After these steps are completed, you can start using FirePHP. All you need to do is callfb
The function is anywhere you want to record. You can also use an optional label and constant to define predefined information, an error, a warning, or a message.
The code is as follows:
$ 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:FirePHP: TRACE constant. you can
View the places where fb is called
Number of rows, class name, and method name
The code is as follows:
Function hello (){
Fb ('Hello World! ', FirePHP: TRACE );
}
Function greet (){
Hello ();
}
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.
Parse FireBug. This small "bug" is a magical and useful HTML/CSS/JavaScript/Ajax debugger. But you...