Reputation: 11308
I'm trying to create custom exception class for codeigniter. Here is my code:
class Ci_exception extends Exception {
var $CI;
function __construct()
{
$this->CI =& get_instance();
}
public function errorMessage()
{
log_message('error', $this->getMessage());
return $this->getMessage();
}
}
This custom class works fine if there is no constructor method. With the construct method the $this->getMessage() method doesn't return any message. Can anyone explain why?
Upvotes: 0
Views: 1824
Reputation: 224942
You need to call the parent's constructor; it's not implicit in PHP. You'll also probably want to accept a $message
parameter.
class Ci_exception extends Exception {
var $CI;
function __construct($message)
{
parent::__construct($message);
$this->CI =& get_instance();
}
public function errorMessage()
{
log_message('error', $this->getMessage());
return $this->getMessage();
}
}
Upvotes: 1