Home >php教程 >PHP源码 >PHP code debugging method encapsulation

PHP code debugging method encapsulation

WBOY
WBOYOriginal
2016-08-04 08:53:371487browse
跳至 [1] [全屏预览]
/**
 * 调试参数中的变量并中断程序的执行,参数可以为任意多个,类型任意,如果参数中含有'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 class="brush:php;toolbar:false">---------------------------------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;
}
Statement:
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