Download the PHP package rasuvaeff/result without Composer

On this page you can find all versions of the php package rasuvaeff/result. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package result

rasuvaeff/result

Latest Stable Version Total Downloads Build Static analysis Psalm level PHP Русская версия

Typed Result<T, E> and Option<T> primitives for PHP 8.3+. The package is framework-free and designed to keep Psalm/PHPStan generic inference useful in application code.

Using an AI coding assistant? llms.txt contains a compact API reference you can share with the model.

Requirements

Installation

Usage

Result

Result<T, E> represents either a successful Ok<T> value or an Err<E> error. unwrap() returns the value for Ok and throws UnwrapException for Err.

Method Description
Result::ok($value) Creates an Ok result.
Result::err($error) Creates an Err result.
Result::fromThrowable($fn) Runs a closure and converts thrown Throwable to Err.
isOk() / isErr() Checks the active branch.
unwrap() Returns the Ok value or throws UnwrapException.
unwrapOr($default) Returns the Ok value or the supplied default.
map($fn) Transforms the Ok value.
mapErr($fn) Transforms the Err error.
flatMap($fn) Chains a closure that returns another Result.
match(ok: $ok, err: $err) Folds both branches to one return value.
value() / error() Returns the branch payload or null.

flatMap() keeps the error channel fixed: the Result returned by the closure must carry the same E error type as the receiver. Use mapErr() first if you need to align error types before chaining.

Option

Option<T> represents either Some<T> or None. Option::fromNullable() converts only null to None; falsey values such as 0, '', and false remain Some.

Method Description
Option::some($value) Creates a Some option.
Option::none() Creates a None option.
Option::fromNullable($value) Converts null to None, other values to Some.
isSome() / isNone() Checks the active branch.
unwrap() Returns the Some value or throws UnwrapException.
unwrapOr($default) Returns the Some value or the supplied default.
map($fn) Transforms the Some value.
filter($predicate) Keeps Some only when the predicate returns true.
toResult($error) Converts Some to Ok and None to Err.

Security

This package does not execute I/O, SQL, shell commands, reflection, or dynamic code. It only stores values and calls closures supplied by your application. Exceptions thrown by closures passed to map(), mapErr(), flatMap(), match(), or filter() are not swallowed; use Result::fromThrowable() at the boundary where exception-to-value conversion is desired.

Examples

See examples/ for runnable scripts.

Script Shows Needs server?
basic.php Result, Option, fromThrowable(), and toResult() usage No

Development

No PHP/Composer on the host. Run commands in Docker via the composer:2 image:

Or with Make:

make test-coverage and make mutation bootstrap pcov inside the composer:2 container because the base image has no coverage driver.

License

BSD-3-Clause


All versions of result with dependencies

PHP Build Version
Package Version
Requires php Version 8.3 - 8.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rasuvaeff/result contains the following files

Loading the files please wait ...