All pastes #504761 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-23 07:54 UTC
rendered paste body
	static function firedebug()
	{
		$debugid= md5(microtime());
		$tracect= 0;

		$bcomma = '';
		$output = "
			<script type=\"text/javascript\">
			if(console) {
				evalue={
		";

		$fooargs = func_get_args();

		if(function_exists('debug_backtrace')) {
			$output.= 'backtrace:[';
			$backtrace = array_reverse(debug_backtrace(), true);
			$bcomma = '';
			foreach($backtrace as $trace) {
				$file = $line = $class = $type = $function = '';
				$args= array();
				extract($trace);
				if(isset($class))	$fname = $class . $type . $function; else	$fname = $function;
				if(!isset($file) || $file=='') $file = '[Internal PHP]'; else $file = basename($file);

				$output.= "{$bcomma}{\nfile:'{$file}',\nline:'{$line}',\nfunction:'{$fname}'";
				if(is_array($args) && count($args) > 0) {
					$output .= ",\nargs:[";
					$comma = '';
					foreach((array)$args as $arg) {
						$output.= "\n\t" . $comma . "'" . gettype($arg) . ': ';
						$argtext = preg_replace('/\r\n|\n/', '\n', print_r( $arg, 1 ) );
						$argtext = str_replace('\\', '\\\\', $argtext );
						$output.= htmlentities( $argtext ) . "'";
						$comma= ', ';
					}
					$output .= "\n]";
				}
				$output.= "}";
				$bcomma = ', ';
			}
			$output .= "\n], \n";
		}
		$output.= "args:[";
		$comma = '';
		foreach( $fooargs as $arg ) {
			$output.= $comma . "'" . gettype($arg) . ': ';
			$output.= htmlentities( print_r( $arg, 1 ) ) . "'";
			$comma= ', ';
		}
		$output.= "
				]};
				console.group('firedebug');
				console.dir(evalue);
				console.groupEnd();
			}
			</script>
		";
		//$output = preg_replace('/^\t+|\n|\r/', '', $output);
		echo $output;
	}