可能的重复:
参考 - 这个符号在PHP中意味着什么?
在,PHP,什么是" - >"运算符调用,你怎么说大声朗读代码?
这是一个非常新手的问题,所以提前道歉,但我已经看过->在示例代码中多次使用过,但我似乎无法在在线教程中找到任何解释它的功能.(主要是因为Google将其视为搜索词 - doh!)
这是一个令我困惑的例子:
<?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 = "someone@example.com";
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();
}
?>
Run Code Online (Sandbox Code Playgroud)
这样的行怎么回事echo $e->errorMessage();?看起来它将变量传递$e给函数errorMessage(),但如果是这样,为什么不以更传统的方式进行呢?
谢谢你的帮助.
| 归档时间: |
|
| 查看次数: |
17348 次 |
| 最近记录: |