php 调试封装类,PHP代码调试debug方法封装

其中的 $dir = realpath(__DIR__); 默认是函数所在目录,显示文件路径用的,具体根据项目结果修改

打印并且终止执行

debug($result);

1.[代码][PHP]代码

/**

* 调试参数中的变量并中断程序的执行,参数可以为任意多个,类型任意,如果参数中含有'debug'参数,刚显示所有的调用过程。

*

*

* debug($var1,$obj1,$array1[,]................);

* debug($var1,'debug');

*

*/

function debug(){

$args = func_get_args();

header('Content-type: text/html; charset=utf-8');

echo "\n

---------------------------------debug 调试信息.---------------------------------\n";

foreach($args as $value){

if(is_null($value)){

echo '[is_null]';

}elseif(is_bool($value) || empty ($value)){

var_dump($value);

}else{

print_r($value);

}

echo "\n";

}

$trace = debug_backtrace();

$next = array_merge(

array (

'line' => '??',

'file' => '[internal]',

'class' => null,

'function' => '[main]'

),$trace[0]

);

$dir = realpath(__DIR__);

if(strpos($next['file'], $dir) === 0){

$next['file'] = str_replace($dir, "", $next['file']);

}

echo "\n---------------------------------debug 调试结束.---------------------------------\n\n文件位置:";

echo $next['file'] . "\t第" . $next['line'] . "行.

\n";

if(in_array('debug', $args)){

echo "\n

";

print_r($trace);

}

//运行时间

exit;

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值