Introduction
PHP's internal Error types are represented by classes that are inherited from Error class. The Error class implements Throwable interface. Properties and methods of Error class are as follows −
properties
- message − The error message
- code − The error code
- file − The filename where the error happened
- line − The line where the error happened
methods
- __construct() − Construct the error object
- getMessage() − Gets the error message
- getPrevious() − Returns previous Throwable
- getCode() − Gets the error code
- getFile() − Gets the file in which the error occurred
- getLine() − Gets the line in which the error occurred
- getTrace() − Gets the stack trace
- getTraceAsString() − Gets the stack trace as a string
- __toString() − String representation of the error
- __clone() − Clone the error
Heirarchy of types of Error classes in PHP is as follows −
Types of Errors
- Error
- ArithmeticError
- DivisionByZeroError
- AssertionError
- CompileError
- ParseError
- TypeError
- ArgumentCountError
- ArithmeticError