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

PHP变量调试函数

PHP中文网
Release: 2016-05-25 17:13:04
Original
1127 people have browsed it

[PHP]代码 

function ss_array_as_string (&$array, $column = 0) {
	$str = "Array(n";
	while(list($var, $val) = each($array)){
		for ($i = 0; $i < $column+1; $i++){
			$str .= "    ";
		}
		$str .= $var. &#39;==>&#39; ;
		$str .= ss_as_string($val, $column+1)." n";
	}
	for ($i = 0; $i < $column; $i++){
		$str .= "    ";
	}
	return $str.);
}
function ss_object_as_string (&$object, $column = 0) {
	if (empty($object->classname)) {
		return "$object";
	}  else {
		$str = $object->classname."( n";
		while (list(,$var) = each($object->persistent_slots)) {
			for ($i = 0; $i < $column; $i++){
				$str .= "    ";
			}   global $$var;   $str .= $var. &#39;==>&#39; ;
			$str .= ss_as_string($$var, column+1)." n";
		}
		for ($i = 0; $i < $column; $i++){
			$str .= "    ";
		}
		return $str.&#39;)&#39;;
	}
}
function ss_as_string (&$thing, $column = 0) {
	if (is_object($thing)) {
		return ss_object_as_string($thing, $column);
	} elseif (is_array($thing)) {
		return ss_array_as_string($thing, $column);
	} elseif (is_double($thing)) {
		return "Double(".$thing.")";
	}  elseif (is_long($thing)) {
		return "Long(".$thing.")";
	}  elseif (is_string($thing)) {
		return "String(".$thing.")";
	}  else {
		return "Unknown(".$thing.")";
	}
}
Copy after login

需要的时候,在程序中简单地加入下面的一条代码即可查看程序中的所使用的变量(包括数组和对象)的类型和值

echo ss_as_string($my_variable);
Copy after login

使用下面的语句,我们可以直接查看程序中所有的变量的值

echo ss_as_string($GLOBALS);
Copy after login

                   

                   

Related labels:
php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template