PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

PHP代码调试方法封装

原创
2016-08-04 08:53:37 1160浏览
跳至 [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;
}
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。