If you are like me, you will not be able to leave FireBug when 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. 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.
Copy Code code 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 shown below
You can also use firephp to track the execution of your program: by usingFirePHP::TRACE常量,你可以在
fb被调用的地方查看
行数、类名和方法名
Copy Code code as follows:
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.