Home> php教程> PHP源码> body text

PHP code debugging method encapsulation

WBOY
Release: 2016-08-04 08:53:37
Original
1408 people have browsed it
跳至 [1][全屏预览]
/** * 调试参数中的变量并中断程序的执行,参数可以为任意多个,类型任意,如果参数中含有'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; }
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!