search
Homephp教程PHP源码PHP变量调试函数

PHP变量调试函数

May 25, 2016 pm 05:13 PM
php

[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.")";
	}
}

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

echo ss_as_string($my_variable);

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

echo ss_as_string($GLOBALS);

                   

                   

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools