これは、カスタム例外に値(以下の例では「username」)を渡す方法ですか?質問は私が使用し__construct()
ますか?重要な変数が過剰に設定されているかどうかを確認するためにカスタム例外を使用していますか?
class customException extends Exception {
public function __construct($e) {
parent::__construct($e); // makes sure variable is set? [1]
$this->e = $e;
}
public function redirect_user() {
if($this->e === "username") {
header("Location: ");
}
}
}
class testing {
public function test() {
try {
if(!isset($_POST['username'])) {
throw new customException("username");
}
}
catch(customException $e) {
$e->redirect_user();
}
}
}
[1] http://php.net/manual/en/language.exceptions.extending.php#example-266
ちなみに、目的はparent::__construct($e)
何ですか?それは冗長ではないでしょうか?