Forum Moderators: coopster

Message Too Old, No Replies

Objects in exception handling

Newbie question

         

Kneek

12:40 pm on Jul 1, 2006 (gmt 0)

10+ Year Member



I'm just learning PHP, and have a question about the following example script:

class myException extends Exception
{
function __toString()
{
return '<table border><tr><td><strong>Exception '. $this->getCode()
. '</strong>: '. $this->getMessage().'<br />'.' in '
. $this->getFile(). ' on line '. $this->getLine()
. '</td></tr></table><br />';
}
}

try
{
throw new myException('A terrible error has occurred', 42);
}
catch (myException $m)
{
echo $m;
}

My question is, where does the object $m come from? I don't see how or when it is created..

coopster

5:14 pm on Jul 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



PHP 5 introduced Type Hinting [php.net]. The object $m is defined in the built in Exception [php.net] class, which is the class you have extended.

Kneek

2:59 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Thanks alot, I understand it now.