Download the PHP package dxw/result without Composer
On this page you can find all versions of the php package dxw/result. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Vendor dxw
Package result
Short Description Result values
License MIT
Homepage https://github.com/dxw/result
Package result
Short Description Result values
License MIT
Homepage https://github.com/dxw/result
Please rate this library. Is it a good library?
Informations about the package result
dxw/result
Meant to be a drop-in replacement for nikita2206/result, with one addition: wrap()
.
wrap()
was inspired by github.com/pkg/errors.
Installation
composer require dxw/result
Usage
Returning values:
function myfunc(): \Dxw\Result\Result
{
if (/* error */) {
// getErr() will return 'something went wrong'
return \Dxw\Result\Result::err('something went wrong');
}
return \Dxw\Result\Result::ok($value);
}
Handling Result
values:
$result = myfunc();
if ($result->isErr()) {
echo sprintf("Error: %s\n", $result->getErr());
exit(1);
}
$value = $result->unwrap();
Returning errors from other errors:
function anotherfunc(): \Dxw\Result\Result
{
$result = myfunc();
if ($result->isErr()) {
// getErr() will return 'got invalid value: something went wrong'
return $result->wrap('got invalid value');
}
// do something with $result->unwrap()
}
All versions of result with dependencies
PHP Build Version
Package Version
Requires
php Version
^7.4||^8.1
The package dxw/result contains the following files
Loading the files please wait ....