Error
Error
Basic controller class
This controller does basic stuff
Properties
type
protected int $type = 'ERR_TYPE_ERROR'errno
public string $errnoerrstr
protected string $errstrerrfile
protected string $errfileerrline
protected int $errlineerrtype
protected string $errtypeerrclass
protected string $errclasscallstack
protected array $callstackshortMessage
protected string $shortMessagecode
The HTTP error code to throw. By default it is 500 Internal Server Error.
protected int $code = 500status
protected string $status = 'Internal Error'statusCodes
public array $statusCodesMethods
__construct
public __construct(): voidgetStatusMessage
Retrieves the status message corresponding to a given status code.
public getStatusMessage(?int $code): stringIf no status code is provided, it uses the instance's current status code.
Parameters
| Parameter | Type | Description |
|---|---|---|
$code | int | The status code to get the message for. If null, the instance's current status code is used. |
setError
Sets the error details based on the provided arguments.
public setError(): voidThis method can handle different types of errors:
- If the first argument is an instance of \Throwable, it extracts the error details from the exception.
- If the first argument is an array, it assumes it's a shutdown error and extracts the details accordingly.
- Otherwise, it assumes it's a standard error and extracts the details from the provided arguments.
getErrorTypeString
Returns a string representation of the given error type.
public getErrorTypeString(int $type): stringParameters
| Parameter | Type | Description |
|---|---|---|
$type | int | The error type constant (e.g., E_ERROR, E_WARNING). |
getErrorMessage
Retrieves the error message with details about the error.
public getErrorMessage(): stringThis method constructs a string that includes the error message, the line number where the error occurred, and the file in which the error was found.
getMessage
Retrieves the error message.
public getMessage(): stringgetTrace
Get the error code.
public getTrace(): voidcleanOutputBuffer
Cleans the output buffer by ending all active output buffering levels.
public cleanOutputBuffer(): voidThis method iterates through all active output buffering levels and ends them using ob_end_clean(). This ensures that any buffered output is discarded and the output buffer is completely cleaned.
runner
Outputs an error message and terminates the script.
public runner(): voidThis method prints a formatted error message that includes the error number, the line number where the error occurred, the file in which the error occurred, and the error string. After printing the error message, the script is terminated with the error number as the exit status.
json
Generates a JSON response containing error details.
public json(): JSONThis method constructs an error array with the following structure:
- 'ok': A boolean indicating the success status (always false).
- 'timestamp': The current timestamp.
- 'error': An array containing error details:
- 'type': The error number.
- 'status': The HTTP status code.
- 'str': The error message.
- 'class' (optional): The class where the error occurred (if display_errors is enabled).
- 'line' (optional): The line number where the error occurred (if display_errors is enabled).
- 'file' (optional): The file where the error occurred (if display_errors is enabled).
- 'trace' (optional): The debug backtrace (if display_errors is enabled).
xml
Generates an XML fault response.
public xml(): XMLThis method constructs an XML structure representing an XML fault response. The response includes details about the error class, error code, status, error message, file, and line number where the error occurred.
text
Generates a detailed text response for an exception.
public text(): TextThis method constructs a formatted string containing information about the exception, including the environment, timestamp, class, error number, file, line, message, and backtrace. The backtrace includes details about each call in the stack, such as the file, line, class, and function.
html
Generates an HTML response for an error.
public html(): HTMLThis method creates a new Layout instance for the error view and populates it with various error details such as environment, error type, error code, error message, file, line, class, type, short message, trace, status code, and execution time. It then renders the view and returns it as an HTML response.
loadStatusCodes
Loads the status codes from the HTTP_Status.dat file and returns an array of status codes.
private loadStatusCodes(): voidGenerated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000