Page 1 of 1

Call to undefined method Exception::setmessage()

Posted: Sun Nov 16, 2008 1:28 am
by Luke
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;
    
    }
 
}

Re: Call to undefined method Exception::setmessage()

Posted: Sun Nov 16, 2008 1:52 am
by requinix
It looks like you copied the error message, right? I see that it's complaining about a "setmessage" function - note the lowercase 'm'.
The message tells you the file and line where the error occurred: I bet if you changed it to an uppercase "M" that would fix it.

Re: Call to undefined method Exception::setmessage()

Posted: Sun Nov 16, 2008 2:55 pm
by Luke
Look at both of the components. Both of them use setMessage(). Also, method names are case insensitive.

Re: Call to undefined method Exception::setmessage()

Posted: Sun Nov 16, 2008 3:42 pm
by Eran
Also, method names are case insensitive
This is not true on linux (works ok on windows).

Also
Call to undefined method qCal_Exception::setmessage()
Where is the code for qCal_Exception?

Re: Call to undefined method Exception::setmessage()

Posted: Sun Nov 16, 2008 3:48 pm
by Luke

Code: Select all

<?php
class qCal_Exception extends Exception {
 
}

Re: Call to undefined method Exception::setmessage()

Posted: Sun Nov 16, 2008 3:51 pm
by Eran
I ran it and it works for me...