>  기사  >  php教程  >  PHP代码调试方法封装

PHP代码调试方法封装

WBOY
WBOY원래의
2016-08-04 08:53:371422검색
跳至 [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;
}
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.