_logging_enabled && $code > 2) {
$this->_logError();
}
}
/**
* Why not log errors? This could be a base method for doing so.
*
*/
protected function _logError() {
/**
* See Blog_Exception::getExceptionName() for how to use get_class()
* ... and please do not generate timestamps via php for storing in databases :)
*/
$store_me = array(
'message' => $this->getMessage(),
'file' => $this->getFile(),
'line' => $this->getLine(),
'trace' => $this->getTraceAsString(),
'exception' => get_class($this),
'occurred_at' => date("Y-m-d H:i:s"),
'code' => $this->getCode()
);
}
/**
* Added for demo purposes
*
* @return Exception
*/
public function getExceptionName() {
return get_class($this);
}
}
/**
* Notice how the class declarations acts like descriptions together with php's get_class
*/
class Blog_Upload_Exception extends Blog_Exception{}
class Blog_Comment_Exception extends Blog_Exception{}
class Blog_Comment_InvalidHtml_Exception extends Blog_Comment_Exception {
protected $_logging_enabled = false;
}
class Surgeon {
public static function continueOperation() {
echo "
Yank yank";
}
}
/**
* Example 1: Use of Custom classes
* Hit F5 repeatedly to make use of the randomly generated exceptions
* Pros:
* Good naming convention makes up for possibly simple or abstract message
* Easy to extend each class since it is separated
* Cons:
* Many classes, possibly many files (for example according to the PEAR/Zend convention "1 class/file")
*/
echo "