Download the PHP package rumd3x/php-go-errors without Composer
On this page you can find all versions of the php package rumd3x/php-go-errors. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rumd3x/php-go-errors
More information about rumd3x/php-go-errors
Files in rumd3x/php-go-errors
Package php-go-errors
Short Description PHP implementation of golang errors package.
License MIT
Informations about the package php-go-errors
php-go-errors
PHP implementation of golang errors package.
Install
Example
Here's an example of usage of the standard Error implementation.
For more information consult the API documentation on the section below.
API
This library provides two utilities that can be used and extended upon:
- A standard interface:
Rumd3x\Errors\ErrorInterface; - A standard implementation:
Rumd3x\Errors\Errorthat already implementsRumd3x\Errors\ErrorInterface;
Error (Interface)
An Rumd3x\Errors\ErrorInterface implementation's constructor should accept the error message string as its first and only parameter.
It should also provide a public method error to convert the instance into the error message:
Error (Implementation)
The standard error implementation full classname is Rumd3x\Errors\Error and already implements Rumd3x\Errors\ErrorInterface.
- The standard error implementation contained in this library is not final, so it can be extended upon.
- It can also be safely treated as a string.
It also provides the following extra methods:
new(Static)newf(Static)
new
The new method, allows to create a new instance of error, but statically, it is functionally the same as using the constructor.
newf
The newf method, allows to create a new instance of error, but it can accept an infinite amount of arguments: (It is functionally the same as formatting a string using sprintf then passing it to the new method)
- The first argument should be the error text, but it accepts the
%notation for formatting; - The rest of the parameters should be the arguments to be formatted on the error text;
Treating error as string
The Rumd3x\Errors\Error or whatever class extend it, can be safely treated as a string, and used alongside one.