如何封装PHP代码调试中的debug方法?

更新于
2026-09-26 01:34:38
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计324个文字,预计阅读时间需要2分钟。

如何封装PHP代码调试中的debug方法?

其内容大致如下:

其中的 $dir=realpath(__DIR__);;默认是函数所在目录,显示文件路径用的,具体根目录项目结果修改+打印并终止执行+debug($result);

1.[代码] [PHP] 代码

* * ** 调试参数中的变量并中断程序执行的流程

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

打印并且终止执行
debug($result);

1.[代码][PHP]代码

/** * 调试参数中的变量并中断程序的执行,参数可以为任意多个,类型任意,如果参数中含有'debug'参数,刚显示所有的调用过程。 * * <code> * debug($var1,$obj1,$array1[,]................); * debug($var1,'debug'); * </code> */ function debug(){ $args = func_get_args(); header('Content-type: text/html; charset=utf-8'); echo "\n<pre>---------------------------------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'] . "行.</pre>\n"; if(in_array('debug', $args)){ echo "\n<pre>"; print_r($trace); } //运行时间 exit; }

如何封装PHP代码调试中的debug方法?
标签:dir

本文共计324个文字,预计阅读时间需要2分钟。

如何封装PHP代码调试中的debug方法?

其内容大致如下:

其中的 $dir=realpath(__DIR__);;默认是函数所在目录,显示文件路径用的,具体根目录项目结果修改+打印并终止执行+debug($result);

1.[代码] [PHP] 代码

* * ** 调试参数中的变量并中断程序执行的流程

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

打印并且终止执行
debug($result);

1.[代码][PHP]代码

/** * 调试参数中的变量并中断程序的执行,参数可以为任意多个,类型任意,如果参数中含有'debug'参数,刚显示所有的调用过程。 * * <code> * debug($var1,$obj1,$array1[,]................); * debug($var1,'debug'); * </code> */ function debug(){ $args = func_get_args(); header('Content-type: text/html; charset=utf-8'); echo "\n<pre>---------------------------------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'] . "行.</pre>\n"; if(in_array('debug', $args)){ echo "\n<pre>"; print_r($trace); } //运行时间 exit; }

如何封装PHP代码调试中的debug方法?
标签:dir