そこで、PHP のマニュアルを読み直していたところ、親例外コンストラクターを呼び出すカスタム例外のコードに関するコメントがあり、この目的が理解できませんでした。
コードは次のとおりです。
class MyException extends Exception
{
// Redefine the exception so message isn't optional
public function __construct($message, $code = 0) {
// some code
// make sure everything is assigned properly
parent::__construct($message, $code);
}
// custom string representation of object
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
}
public function customFunction() {
echo "A custom function for this type of exception\n";
}
}
次の論理がわかりません。
//make sure everything is assigned properly
parent::__construct($message, $code);
なぜこれが行われるのかについての論理は役に立ちます。