Download the PHP package prvious/result without Composer

On this page you can find all versions of the php package prvious/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

Result

CI PHP

A tiny, typed way to return either a value or an expected error—without turning normal control flow into exceptions.

PHP 8.4+. No runtime dependencies. Framework agnostic. Friendly to PHPStan and other analyzers that understand PHPDoc generics.

Installation

Basic usage

The return type describes both possible outcomes: a float when the operation succeeds, or a string when it cannot be completed.

Use match() to handle both:

Exactly one callback runs, and its value is returned directly—it is not wrapped in another Result.

Creating results

Both variants accept any PHP value, including objects, enums, arrays, scalars, Throwable instances, and null.

API at a glance

Method On Ok On Err
isOk() true false
isErr() false true
unwrap() Returns the value Throws Panic
error() Throws Panic Returns the error
match($ok, $err) Calls $ok Calls $err
map($callback) Transforms the value Preserves the error
mapError($callback) Preserves the value Transforms the error
andThen($callback) Runs the next Result operation Short-circuits

PHPStan narrows the variant after isOk() or isErr():

Transforming and chaining

Use map() when the callback returns a plain value:

Use mapError() to translate an error into the vocabulary of the current operation:

This changes Result<float, string> into Result<float, array{message: string}> without touching an existing Ok.

Use andThen() when the next callback already returns a Result:

The first Err stops the chain. andThen() returns the callback's result directly, so it never creates a nested Result<Result<...>>.

About Panic

Panic means the Result API was used incorrectly: unwrap() was called on an Err, or error() was called on an Ok.

It extends LogicException, exposes the wrongly accessed payload through $panic->payload, and is not a third Result variant. Do not catch it for business flow—use match(), isOk(), or isErr() instead.

If an incorrectly unwrapped Err contains a Throwable, that throwable is preserved as $panic->getPrevious().

Results are not exception replacement

Use Err for outcomes the caller is expected to handle: a duplicate email, an expired invite, a declined payment, or a missing domain object.

Unexpected database, network, filesystem, and provider failures should normally remain exceptions. This package never catches exceptions thrown inside match(), map(), mapError(), or andThen(), so reporting, retries, and transaction rollbacks continue to work normally.

Frameworks and data objects

The package has no Laravel integration, service provider, or configuration. A Laravel action can return a Result in the same way, and an Ok may contain a Spatie Data object without making spatie/laravel-data a package dependency.

Applications running PHP 8.5 may add #[\NoDiscard] to methods returning Result to warn when the outcome is ignored. The package itself supports PHP 8.4, so it does not apply that attribute.

Development

composer check runs Composer validation, formatting, linting, static analysis, Rector, and the test suite. Coverage is enforced at 100 percent.

License

Result is open-source software licensed under the MIT License.


All versions of result with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
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 prvious/result contains the following files

Loading the files please wait ...