Jest to dosłownie odrobinę zmieniona klasa Exception.
<?php class Error { protected $message='Unknown exception'; protected $desc; protected $code; protected $file; protected $line; protected $trace; public function __construct(string $desc=NULL, int $code=NULL, string $message=NULL) { { $this->message = $message; } $this->code = $code; $this->file = __FILE__; $this->line = __LINE__; } final function get_message() { return $this->message; } final function get_desc() { return $this->desc; } final function get_code() { return $this->code; } final function get_file() { return $this->file; } final function get_line() { return $this->line; } final function get_trace() { return $this->trace; } public function __toString() { return '<div style="width:90%; margin:0 auto; padding:5px; background-color:#555; border:1px solid #000;"> <b>Exception '.$this->get_code().':</b> '.$this->get_desc(). '<br><b>File:</b> '.$this->get_file().' <b>Line:</b> '.$this->get_line(). '<br><b>Error:</b> '.$this->get_desc(); } } ?>
Wywołanie błędu:
Wywołuję go specjalnie zmieniając nazwę użytkownika dostępu do bazy na niepoprawną.
<?php public function connect($db_host,$db_user,$db_pass,$db_name,$db_port) { try { $this->db_host = $db_host; $this->db_port = $db_port; $this->db_name = $db_name; if(true == ($this->db_link = @mysqli_connect($db_host,$db_user,$db_pass,$db_name,$db_port))) { return true; } else { throw new Error('Connection Problem', 0); } } catch (Error $e) { } } ?>
Pojawia mi się błąd:
Cytat
Catchable fatal error: Argument 1 passed to Error::__construct() must be an instance of string, string given, called in D:\WWW\orglee\class\class_mysql.php on line 70 and defined in D:\WWW\orglee\class\class_exception.php on line 13
Co jest nie tak ? Dlaczego wyświetla mi ten błąd i co on oznacza ? Na googlach znalazłem tylko ten błąd w CMS Joomla (błąd dotyczył template'a) a rozwiązania błędu nie było.