Direkt zum Inhalt | Direkt zur Navigation

Benutzerspezifische Werkzeuge
Anmelden
Home Produkte

SaaS

Software as a Service

Hosting

schon ab €14,00!

Software-Entwicklung

Wir programmieren alles, was wir hosten.

Lösungen

Web & E-Commerce

Kollaboration

Hosting & Skalierbarkeit

Support Open Source

Python

PHP

Weitere

Über uns

Kontakt

Wir

Sie sind hier: Startseite Open Source PHP Cron.php4 Exception.php - Sourcecode und Dokumentation

Exception.php - Sourcecode und Dokumentation

<?php

/*
 * I WANT Exceptionhandling in php4. At least something that feels like it.
 */

if (!$GLOBALS["EXCEPTIONS"]) $GLOBALS["EXCEPTIONS"] = array();

if(!class_exists('EException')){

	function ecatch($code=0) {
		if (!$code) {
			if (count($GLOBALS["EXCEPTIONS"]))
				return array_pop($GLOBALS["EXCEPTIONS"]);
		}
		for ($i=0; $i<count($GLOBALS["EXCEPTIONS"]); $i++) {
			if ($GLOBALS["EXCEPTIONS"][$i]->getCode() == $code) {
				$e = $GLOBALS["EXCEPTIONS"][$i];
				unset($GLOBALS["EXCEPTIONS"][$i]);
				return $e;
			}
		}
		return null;
	}

	class EException{
		var $_message = '';
		var $_code = 0;
		var $_line = 0;
		var $_file = '';
		var $_trace = null;

		function EException($message = 'Unknown exception', $code = 0){
			$this->_message = $message;
			$this->_code = $code;
			$this->_trace = debug_backtrace();
			$x = array_shift($this->_trace);
			$this->_file = $x['file'];
			$this->_line = $x['line'];
			
			$GLOBALS["EXCEPTIONS"][] =& $this;
		}

		function __construct($message = 'Unknown exception', $code = 0){
			$this->EException($message, $code);
		}

		function getMessage(){
			return $this->_message;
		}
		function getCode(){
			return $this->_code;
		}
		function getFile(){
			return $this->_file;
		}
		function getLine(){
			return $this->_line;
		}
		function getTrace(){
			return $this->_trace;
		}
		function getTraceAsString(){
			$s = '';
			foreach($this->_trace as $i=>$item){
				foreach($item['args'] as $j=>$arg)
					$item['args'][$j] = print_r($arg, true);
				$s .= "#$i " . (isset($item['class']) ? $item['class'] . $item['type'] : '') . $item['function']
				. '(' . implode(', ', $item['args']) . ") at [$item[file]:$item[line]]\n";
			}
			return $s;
		}
		function printStackTace(){
			echo $this->getTraceAsString();
		}
		function toString(){
			return $this->getMessage();
		}
		function __toString(){
			return $this->toString();
		}
	}
}
?>