Download the PHP package maplephp/blunder without Composer
On this page you can find all versions of the php package maplephp/blunder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maplephp/blunder
More information about maplephp/blunder
Files in maplephp/blunder
Package blunder
Short Description Blunder is a well-designed PHP error handling framework.
License Apache-2.0
Homepage https://wazabii.se
Rated 5.00 based on 1 reviews
Informations about the package blunder
MaplePHP Blunder
Blunder is a pretty error handling framework for PHP. It provides a pretty, user-friendly interface that simplifies debugging with excellent memory management. Blunder offers various handlers, including HTML, JSON, XML, CLI, plain text, and silent modes, allowing flexible error presentation. Seamlessly integrating with tools like the PSR-7 and PSR-3 compliant MaplePHP Log library, Blunder is an excellent choice for managing errors in PHP applications, helping users easily identify and resolve issues.
With Blunder, you can easily control how errors are handled—whether you want to suppress specific severities, redirect them to logging, or assign them to different handlers. For example, you can automatically log all Deprecated warnings while keeping Warnings visible for debugging. This level of customization ensures a smooth and efficient error-handling experience tailored to your needs.
Installation
Installation with composer
Pretty Example
Here is a simple example to load the pretty error interface:
Handlers
All handlers utilize the namespace MaplePHP\Blunder\Handlers\[TheHandlerName]
.
- HtmlHandler: A user-friendly and visually appealing handler.
- TextHandler: Outputs a minified HTML text.
- PlainTextHandler: Outputs minified plain text.
- JsonHandler: Outputs errors as JSON.
- XmlHandler: Outputs errors as XML.
- CliHandler: Prompt handler for the command-line interface (CLI)
- SilentHandler: Suppresses error output but can log errors to files. You can choose to output fatal errors if necessary.
Excluding Specific Error Severities from the Handler
With Blunder, you can exclude specific error severities from the handler. This allows you to control how certain errors are processed without affecting the overall error handling behavior.
1. Exclude Severity Levels
This method removes the specified severities from Blunder’s handler, allowing them to be processed by PHP’s default error reporting.
Effect:
E_DEPRECATED
andE_USER_DEPRECATED
will no longer be handled by Blunder.- PHP’s default error handling will take over for these severities.
2. Exclude and Redirect Severities
Instead of letting PHP handle the excluded severities, you can redirect them to a custom function for further processing, such as logging.
Behavior:
return true;
→ Completely suppresses errors of the excluded severities.return false;
→ Uses PHP’s default error handler for the excluded severities.return null|void;
→ Keeps using Blunder’s error handler as usual.
Example Use Case:
- Log warnings instead of displaying them.
- Ensure deprecated notices are logged but not shown in production.
3. Redirect Excluded Severities to a New Handler
You can also redirect excluded severities to a completely different error handler.
Effect:
E_WARNING
andE_USER_WARNING
will be processed byJsonHandler
instead ofHtmlHandler
or PHP’s default error handling.
Note:
You can find a full list of available PHP error severities here.
Enabling or Disabling Trace Lines
This allows you to control the level of detail shown in error messages based on your debugging needs. You can customize this behavior using the configuration:
Options:
true
→ Enables trace lines (default in all cases except for in the CliHandler).false
→ Disables trace lines, making error messages cleaner.
This allows you to control the level of detail shown in error messages based on your debugging needs.
Remove location headers
This will remove location headers and make sure that no PHP redirect above this code will execute.
Setting the Exit Code for Errors
To make Blunder trigger a specific exit code when an error occurs. This is useful in unit testing and CI/CD, ensuring tests fail on errors.
Event Handling
You can use Blunder's event functionality to handle errors, such as logging them to a file. The example below shows how to display a pretty error page in development mode and log errors in production.
1. Install MaplePHP Log
We use MaplePHP Log in the example, a PSR-3 compliant logging library.
2. Create an Event
Here is a complete example with explanatory comments.
HTTP Messaging
The Blunder Run
class can take two arguments. The first argument is required and should be a class handler (HandlerInterface
). The second argument is optional and expects an HTTP message class used to pass an already open PSR-7 response and ServerRequest
instance instead of creating a new one for better performance.
Exception Chaining
When rethrowing an exception with a different type, PHP resets the file and line number to the location of the new throw
statement. This can make debugging harder, as the error message will point to the wrong file instead of the original source of the exception.
To preserve the original exception’s file and line number while changing its type, you can use the preserveExceptionOrigin
method provided by Blunder.