Possible Duplicates:
Reference - What does this symbol mean in PHP?
In, PHP, what is the “->” operator called and how do you say it when reading code out loud?
This is a really newbie question, so apologies in advance, but I've seen ->
used several times in example code, but I can't seem to find any explanation in online tutorials for what it does. (Mainly because Google ignores it as a search term - doh!)
Here's an example that confuses me:
<?php
class customException extends Exception
{
public function errorMessage()
{
//error message
$errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile()
.': <b>'.$this->getMessage().'</b> is not a valid E-Mail address';
return $errorMsg;
}
}
$email = "[email protected]";
try
{
//check if
if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE)
{
//throw exception if email is not valid
throw new customException($email);
}
//check for "example" in mail address
if(strpos($email, "example") !== FALSE)
{
throw new Exception("$email is an example e-mail");
}
}
catch (customException $e)
{
echo $e->errorMessage();
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
What is going on in lines such as echo $e->errorMessage();
? It looks like its passing the variable $e
to the function errorMessage()
, but if so, why not just do it in the more traditional way?
Thanks for any help.