- Edited
Fatal error: Declaration of Exceptions::getMessage() must be compatible with Throwable::getMessage(): string in /var/www/html/php-books/php-and-mysql-web-development/chapter07/user-defined-exceptions-pag-202/exception-class.php on line 21
https://www.php.net/manual/en/language.exceptions.extending.php
<?php
class Exceptions implements Throwable
{
protected $message = 'Unknown exception'; // exception message
private $string; // __toString cache
protected $code = 0; // user defined exception code
protected $file; // source filename of exception
protected $line; // source line of exception
private $trace; // backtrace
private $previous; // previous exception if nested exception
public function __construct($message = '', $code = 0, Throwable $previous = null){
}
final private function __clone(){
} // Inhibits cloning of exceptions.
final public function getMessage(){
} // message of exception
final public function getCode(){
} // code of exception
final public function getFile(){
} // source filename
final public function getLine(){
} // source line
final public function getTrace(){
} // an array of the backtrace()
final public function getPrevious(){
} // previous exception
final public function getTraceAsString(){
} // formatted string of trace
// Overrideable
public function __toString() {
} // formatted string for display
}
?>
phpstorm with php 8.2 returns these errors
Private methods cannot be final as they are never overridden by other classes:17
Return type declaration must be compatible with Throwable->getMessage() : string:21
Return type declaration must be compatible with Throwable->getFile() : string:29
Return type declaration must be compatible with Throwable->getLine() : int:33
Return type declaration must be compatible with Throwable->getTrace() : array:37
Return type declaration must be compatible with Throwable->getPrevious() : null|\Throwable:41
Return type declaration must be compatible with Throwable->getTraceAsString() : string:45
'__toString' method must return a string:49