FirePHP详解

FirePHP使用详解

1、面向对象API(Object Oriented API)

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() */);

2、面向过程API

require_once('FirePHPCore/fb.php');

fb($var);
fb($var, 'Label');
fb($var, FirePHP::*);
fb($var, 'Label', FirePHP::*);

3、参数说明

// Defaults:
$options = array('maxObjectDepth' => 5,
                 'maxArrayDepth' => 5,
                 'maxDepth' => 10,
                 'useNativeJsonEncode' => true,
                 'includeLineNumbers' => true);

$firephp->getOptions();
$firephp->setOptions($options);
FB::setOptions($options);

$firephp->setObjectFilter('ClassName',
                           array('MemberName'));

4、错误、异常及断点处理

$firephp->registerErrorHandler(
            $throwErrorExceptions=false);
$firephp->registerExceptionHandler();
$firephp->registerAssertionHandler(
            $convertAssertionErrorsToExceptions=true,
            $throwAssertionExceptions=false);

try {
  throw new Exception('Test Exception');
} catch(Exception $e) {
  $firephp->error($e);  // or FB::
}

5、分组

$firephp->group('Test Group');
$firephp->log('Hello World');
$firephp->groupEnd();

$firephp->group('Collapsed and Colored Group',
                array('Collapsed' => true,
                      'Color' => '#FF00FF'));

6、记录信息

$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::*);

7、分表

$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);

8、跟踪

$firephp->trace('Trace Label');  // or FB::

fb('Trace Label', FirePHP::TRACE);

官方文档:http://www.firephp.org/HQ/Use.htm

补充说明的部分:

FirePHP是一个利用Firebug console栏输出调试信息方便程序调试。这一切只需要调用几个简单的函数。

他看起来是怎么个样子?
<?php
FB::log('Log message');
FB::info('Info message');
FB::warn('Warn message');
FB::error('Error message');
?>

为什么要用它?在开发环境下正常运行的程序放在生产环境出问题了!我期望可以在生产环境中进行修改。但不期望客户看到这一切的发生。请选择FirePHP。常规的PHPUnit确实能帮助大家进行自动化测试。但我期望更为直观的结果显示。让我知道程序内发生了什么。看到结果按约输出心里才放心。

请选择FirePHP。常规var_export()显示在页面上,破坏了页面结构,影响了界面开发人员的工作。请选择FirePHP。更多好处等待您的发现。


开始我们的FirePHP之旅:
1、确认您安装了FireFox(对FF有持有偏见,抵制FF的可以走了)。
FireFox: http://www.mozillaonline.com/
2、确认您安装了Firebug。
Firebug: https://addons.mozilla.org/zh-CN/firefox/addon/1843
3、安装FirePHP插件。
FirePHP: https://addons.mozilla.org/zh-CN/firefox/addon/6149
4、安装FirePHP服务器端。
这里有两种安装方式一种通过pear安装,另一种直接下载代码包。
这里建议使用第二种方式。
方式一 通过pear安装:
pear安装方式请参见 Netbeans新增PHPUnit支持 试用手记  http://bbs.phpchina.com/thread-104215-1-1.html
以下为FirePHP安装所需命令。pear channel-discover pear.firephp.org

pear install firephp/FirePHPCore 复制代码 方式二 直接下载代码包:
下载地址:  http://www.firephp.org/DownloadR ... y-FirePHPCore-0.2.1
5、服务端使用方式。
a、引入代码require_once('FirePHPCore/fb.php'); // 建议引入此文件即可。文件目录自行安排。使用pear方式安装也是这样引入。 复制代码 b、开启客户端
开启Firebug 控制台、脚本、网络。
将当前网站添加入FirePHP允许站点(十分容易自己熟悉一下就知道了)。
b、常规使用 
<?php
include_once('FirePHP/fb.php');
FB::log('Hello World !'); // 常规记录
FB::group('Test Group A'); // 记录分组
// 以下为按照不同类别或者类型进行信息记录
FB::log('Plain Message');
FB::info('Info Message');
FB::warn('Warn Message');
FB::error('Error Message');
FB::log('Message','Optional Label');
FB::groupEnd();
FB::group('Test Group B');
FB::log('Hello World B');
FB::log('Plain Message');
FB::info('Info Message');
FB::warn('Warn Message');
FB::error('Error Message');
FB::log('Message','Optional Label');
FB::groupEnd();
// 将信息作为table输出
$table[] = array('Col 1 Heading','Col 2 Heading','Col 2 Heading');
$table[] = array('Row 1 Col 1','Row 1 Col 2','Row 1 Col 2');
$table[] = array('Row 2 Col 1','Row 2 Col 2');
$table[] = array('Row 3 Col 1','Row 3 Col 2');
FB::table('Table Label', $table);
// 在异常处理中使用FirePHP
class MyException extends Exception{
    
    public function  __construct($message, $code) {
        parent::__construct($message, $code);
    }
    
    public function log(){
        FB::log($this->getMessage());
    }
}

try{
    echo 'MoXie';
    throw new MyException('some description',1);
}catch(MyException $e){
    $e->log();
}
?>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值