by eash on Wednesday, 23 September 2009
Firephp


FirePHP enables you to log to your Firebug Console using a simple PHP method call.

All data is sent via response headers and will not interfere with the content on your page.

FirePHP is ideally suited for AJAX development where clean JSON and XML responses are required.

 

How to Use:

 

Use the object oriented API when you want to keep the logging statements in your application. It will provide more flexibility and future-proof your code.

Logging is enabled by default. You can disable it with setEnabled(false). Use this method to disable logging on your live site for everyone except authorized users.

There is also an overloaded method equivalent to fb() (see Procedural API) called FB::send().

 

require_once('FirePHPCore/FirePHP.class.php');
$firephp = FirePHP::getInstance(true);
$firephp-> *
 
require_once('FirePHPCore/fb.php');
FB:: *
 
$firephp->setEnabled(false); // or FB::
 
FB::send(/* See fb() */);

Procedural API

The procedural API consists of one function. It is fast to type and the function arguments are overloaded.

Use the fb() function for ad-hock debugging and development when you intend to remove the logging statements again.

 

require_once('FirePHPCore/fb.php'); 
fb($var)
fb($var, 'Label')
fb($var, FirePHP::*)
fb($var, 'Label', FirePHP::*)

 

 

Options & Object Filters

maxObjectDepthMaximum depth to traverse objects.
maxArrayDepthMaximum depth to traverse arrays.
useNativeJsonEncodeSet to FALSE to use JSON encoder included with FirePHPCore instead of json_encode().
includeLineNumbersInclude File and Line information in message.

To exclude specific members when logging objects use setObjectFilter().

 

// Defaults:
$options = array('maxObjectDepth' => 10,
'maxArrayDepth' => 20,
'useNativeJsonEncode' => true,
'includeLineNumbers' => true);
 
$firephp->getOptions();
$firephp->setOptions($options);
FB::setOptions($options);
$firephp->setObjectFilter('ClassName',
array('MemberName'));

 

 

Error, Exception & Assertion Handling

Convert E_WARNING, E_NOTICE, E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE and E_RECOVERABLE_ERROR errors to ErrorExceptions and send all Exceptions to Firebug automatically if desired.

Assertion errors can be converted to exceptions and thrown if desired.

You can also manually send caught exceptions to Firebug.

 

$firephp->registerErrorHandler(
$throwErrorExceptions=true);
$firephp->registerExceptionHandler();
$firephp->registerAssertionHandler(
$convertAssertionErrorsToExceptions=true,
$throwAssertionExceptions=false);
 
try {
throw new Exception('Test Exception');
} catch(Exception $e) {
$firephp->error($e); // or FB::
}
 

Groups

In many cases it is useful to group logging messages together. Groups can be nested programatically and expanded/contracted by the user.

By default groups are expended in the firebug console.

You can change the color of the group label by specyfying a standard HTML color value
 $firephp->group('Test Group');
$firephp->log('Hello World');
$firephp->groupEnd();
 
$firephp->group($'Collapsed and Colored Group',
array('Collapsed' => true,
'Color' => '#FF00FF'));
 

Logging Messages

Priority Styling
These logging methods follow the four Firebug logging priorities. Add an optional label as a second argument to any of these methods.

If you are using the fb() function use the FirePHP::LOG, FirePHP::INFO, FirePHP::WARN, FirePHP::ERROR constants.

 $firephp->log('Plain Message');     // or FB::
$firephp->info('Info Message'); // or FB::
$firephp->warn('Warn Message'); // or FB::
$firephp->error('Error Message'); // or FB::
 
$firephp->log('Message','Optional Label');
 
$firephp->fb('Message', FirePHP::*);
 

Tables
You can log tables of information. Firebug will display the Table Label and allow the user to toggle the display of the table. The first row of the table is automatically used as the heading and the number of columns is dynamically determined.

If you are using the fb() function use the FirePHP::TABLE constant.

 $table   = array();
$table[] = array('Col 1 Heading','Col 2 Heading');
$table[] = array('Row 1 Col 1','Row 1 Col 2');
$table[] = array('Row 2 Col 1','Row 2 Col 2');
$table[] = array('Row 3 Col 1','Row 3 Col 2');
 
$firephp->table('Table Label', $table); // or FB::
 
fb($table, 'Table Label', FirePHP::TABLE);
 

Traces
You can send a backtrace showing File, Line, Class, Method and Function information including Arguments to clearly show the execution path up to the point in your code where you triggered the trace.

If you are using the fb() function use the FirePHP::TRACE constant.

 $firephp->trace('Trace Label');  // or FB::
 
fb('Trace Label', FirePHP::TRACE);
 

Dumping Variables

You can dump a variable to the Server tab of the Firebug Request Inspector. To get to the Request Inspector expand a request in the Console or Net panels.

If you are using the fb() function use the FirePHP::DUMP constant.

 $firephp->dump('Key', $variable);  // or FB::
 
$firephp->fb($variable, 'Key', FirePHP::DUMP);
 
PHP4 Notes






Make sure to use the PHP4 versions of the library files.

FirePHP::getInstance() auto creates a global FirePHP object called $FirePHP_Instance and returns a reference to it. Make sure to remember the & symbol when assigning the returned reference to ensure the object is not copied.

All FirePHP::* class constants are accessible via global FirePHP_* constants.

Exception handling functionality will not work as there is no exception support in PHP4. registerErrorHandler() always logs errors to FirePHP.

 
require_once('FirePHPCore/FirePHP.class.php4');
require_once('FirePHPCore/fb.php4');
 
$firephp =& FirePHP::getInstance(true);
 
fb($var, FirePHP_*)
 

 

 



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering