Call to undefined method Exception::setmessage()
Posted: Sun Nov 16, 2008 1:28 am
I have encountered a very strange error. I have extended the standard Exception class in the following two classes. The qCal_Exception_Property one works just fine, but when I instantiate qCal_Exception_Component, it tells me "Call to undefined method qCal_Exception::setmessage()". WTF?? Does this make sense to anybody?
Code: Select all
<?php
/**
* This is used for component-related exceptions
*/
class qCal_Exception_Component extends qCal_Exception {
protected $component;
/**
* Replaces {COMPONENT} with the component name. This is so that when reporting messages,
* you can simply do throw new qCal_Component_Exception("{COMPONENT} did something wrong");
*/
public function setMessage($message) {
if ($this->component instanceof qCal_Component) {
$message = str_replace("{COMPONENT}", $this->component->getName(), $message);
}
return parent::setMessage($message);
}
public function setComponent(qCal_Component $component) {
$this->component = $component;
}
public function getComponent() {
return $this->component;
}
}Code: Select all
<?php
/**
* This is used for property-related exceptions
*/
class qCal_Exception_Property extends qCal_Exception {
protected $property;
/**
* Replaces {PROPERTY} with the property name. This is so that when reporting messages,
* you can simply do throw new qCal_Property_Exception("{PROPERTY} did something wrong");
*/
public function setMessage($message) {
if ($this->property instanceof qCal_Property) {
$message = str_replace("{PROPERTY}", $this->property->getName(), $message);
}
return parent::setMessage($message);
}
public function setProperty(qCal_Property $property) {
$this->property = $property;
}
public function getProperty() {
return $this->property;
}
}