Call to undefined method Exception::setmessage()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Call to undefined method Exception::setmessage()

Post 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;
    
    }
 
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

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

Post by Luke »

Look at both of the components. Both of them use setMessage(). Also, method names are case insensitive.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post 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?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

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

Post by Luke »

Code: Select all

<?php
class qCal_Exception extends Exception {
 
}
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post by Eran »

I ran it and it works for me...
Post Reply