<?php
/* 如果一封电子邮件被视为非法,则InvalidEmailException 类将通知站点管理员*/class InvalidEmailException extends Exception{ function _ _construct($message, $email) {
$this->message=$message;
$this->notifyAdmin($email);
}
private function notifyAdmin($email){
mail("[email protected]", "INVALID EMAIL", $email, "From:[email protected]");
}
}
/* Subscribe类验证电子邮件地址并将其加入数据库*/ class Subscribe{
function validateEmail($email){ try {
if ($email==" "){
throw new Exception("You must enter an e-mail address!");
}else{
list($user, $domain)= explode("@", $email); if(! checkdnsrr($domain, "MX"))
throw newInvalidEmailException(
"Invalid e-mail address!", $email);
else
return 1;
}
}catch (Exception $e) {
echo $e->getMessage();
} catch(InvalidEmailException $e) {
echo $e->getMessage();
$e->notifyAdmin(email);
}
}问: 类Subscribe 为什么能调用类InvalidEmailException 的私有方法 notifyAdmin()
感谢
/* 如果一封电子邮件被视为非法,则InvalidEmailException 类将通知站点管理员*/class InvalidEmailException extends Exception{ function _ _construct($message, $email) {
$this->message=$message;
$this->notifyAdmin($email);
}
private function notifyAdmin($email){
mail("[email protected]", "INVALID EMAIL", $email, "From:[email protected]");
}
}
/* Subscribe类验证电子邮件地址并将其加入数据库*/ class Subscribe{
function validateEmail($email){ try {
if ($email==" "){
throw new Exception("You must enter an e-mail address!");
}else{
list($user, $domain)= explode("@", $email); if(! checkdnsrr($domain, "MX"))
throw newInvalidEmailException(
"Invalid e-mail address!", $email);
else
return 1;
}
}catch (Exception $e) {
echo $e->getMessage();
} catch(InvalidEmailException $e) {
echo $e->getMessage();
$e->notifyAdmin(email);
}
}问: 类Subscribe 为什么能调用类InvalidEmailException 的私有方法 notifyAdmin()
感谢
....................
} catch(InvalidEmailException $e) {
echo $e->getMessage();
$e->notifyAdmin($email);
}catch (Exception $e) {
echo $e->getMessage();
}
...........................