Location: PHPKode > projects > PHP SiteBuilder > include/class.helpers.php
<?php
/**  Functions to help debug and development.
 *
 *	@file: 	class.helpers.php
 *	@date:	2000-05-17
 *
 *	$Id: class.helpers.php,v 1.3 2001/08/31 13:44:30 phps Exp $
 *
 *	functions:
 *		ss_as_string (&$thing, $column = 0) # found on e-gineer.com
 *
		ss_as_string
		Examples of Usage:
	 	Now we can see the state of any variable by just doing: 
			$h = new helpers;
			echo $h->ss_as_string($my_variable);
		
	*	We can see the value of all variables currently defined in the PHP namespace with: 
			
			echo $h->ss_as_string($GLOBALS);
			
	*	JROE: "one-liner example I use in my code for convenience. Put $tmpVarForDebug to whatever You like.
		//debug
		$tmpVarForDebug	= $arr; 	if (true) {	include ("include/class.helpers.php");$h = new helpers;	echo "<hr>".$h->ss_as_string($tmpVarForDebug)."<hr>";}
 */

if 	(defined('__class_helpers')) return;
	  define('__class_helpers', 1 );



class helpers {
	var $x	= "";
	var $separator = "HELK-";

	function ss_array_as_string (&$array, $column = 0) {
		global $separator;
	    $str = "Array(<BR>\n";
	    while(list($var, $val) = each($array)){
			for ($i = 0; $i < $column+1; $i++){
	            $str .= $separator;
	        }
	        $str .= $var.' ==> ';
	        $str .= $this->ss_as_string($val, $column+1)."<BR>\n";
		}
	  	for ($i = 0; $i < $column; $i++){
			$str .= $separator;
	    }
		return $str.")<BR>\n";
	}
		
	function ss_object_as_string (&$object, $column = 0) {
		global $separator;
		if (empty($object->classname)) {
			return "$object";    }
		else {
	        $str = $object->classname."(<BR>\n";
	        while (list(,$var) = each($object->persistent_slots)) {
	            for ($i = 0; $i < $column; $i++){
	                $str .= $separator;
				}
	            global $$var;
				$str .= $var.' ==> ';
	            $str .= $this->ss_as_string($$var, column+1)."<BR>\n";
			}
			for ($i = 0; $i < $column; $i++){
	        	$str .= $separator;
			}
			return $str.')';
	    }
	}
	
	function ss_as_string (&$thing, $column = 0) {
	    if (is_object($thing)) {
	        return $this->ss_object_as_string($thing, $column);
		}
	    elseif (is_array($thing)) {
	        return $this->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.")";
		}
	}


}	// end class helpers

?>
Return current item: PHP SiteBuilder