Exception class fix for php 4 //PHP Class
1 2 if(!class_exists('Exception')){ 3 class Exception{ 4 var $_message = ''; 5 var $_code = 0; 6 var $_line = 0; 7 var $_file = ''; 8 var $_trace = null; 9 10 function Exception($message = 'Unknown exception', $code = 0){ 11 $this->_message = $message; 12 $this->_code = $code; 13 $this->_trace = debug_backtrace(); 14 $x = array_shift($this->_trace); 15 $this->_file = $x['file']; 16 $this->_line = $x['line']; 17 } 18 19 function __construct($message = 'Unknown exception', $code = 0){ 20 $this->Exception($message, $code); 21 } 22 23 function getMessage(){ 24 return $this->_message; 25 } 26 function getCode(){ 27 return $this->_code; 28 } 29 function getFile(){ 30 return $this->_file; 31 } 32 function getLine(){ 33 return $this->_line; 34 } 35 function getTrace(){ 36 return $this->_trace; 37 } 38 function getTraceAsString(){ 39 $s = ''; 40 foreach($this->_trace as $i=>$item){ 41 foreach($item['args'] as $j=>$arg) 42 $item['args'][$j] = print_r($arg, true); 43 $s .= "#$i " . (isset($item['class']) ? $item['class'] . $item['type'] : '') . $item['function'] 44 . '(' . implode(', ', $item['args']) . ") at [$item[file]:$item[line]]\n"; 45 } 46 return $s; 47 } 48 function printStackTace(){ 49 echo $this->getTraceAsString(); 50 } 51 function toString(){ 52 return $this->getMessage(); 53 } 54 function __toString(){ 55 return $this->toString(); 56 } 57 } 58 }