PHPackages                             ganglio/please - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ganglio/please

ActiveLibrary

ganglio/please
==============

PHP Functional Try

v1.1.0.2(10y ago)020MITPHPPHP &gt;=5.4.0

Since Mar 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/ganglio/Please)[ Packagist](https://packagist.org/packages/ganglio/please)[ Docs](http://www.github.com/ganglio/Please)[ RSS](/packages/ganglio-please/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Please
======

[](#please)

Functional and polite implementation of try/catch

[![Latest Stable Version](https://camo.githubusercontent.com/9ba9021d588b32b46e269b5333ad0b2fc86b53625ce5103cbdf96a9a29e83668/68747470733a2f2f706f7365722e707567782e6f72672f67616e676c696f2f706c656173652f762f737461626c65)](https://packagist.org/packages/ganglio/Please)[![Build Status](https://camo.githubusercontent.com/df2745bd7552f4c6cf72e66d5e34d871f7af39e2d89a98530bb85fc45adaccac/68747470733a2f2f7472617669732d63692e6f72672f67616e676c696f2f506c656173652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ganglio/Please)[![codecov.io](https://camo.githubusercontent.com/1db887e7a01a58ef414177cb54ea0136c9998ce73517481d7216f31c7ccc0874/687474703a2f2f636f6465636f762e696f2f6769746875622f67616e676c696f2f506c656173652f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/ganglio/Please?branch=master)[![Code Climate](https://camo.githubusercontent.com/3815516da77d216b637b82aa736ed28191fa744bb6f0ece0056a0cbae8d1737c/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f67616e676c696f2f506c656173652f6261646765732f6770612e737667)](https://codeclimate.com/github/ganglio/Please)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/79ae2f2fe4c5b5c7ed9f75db2c073cdafe39297476bf2f2443b97b6fd0bab23d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67616e676c696f2f506c656173652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ganglio/Please/?branch=master)[![License](https://camo.githubusercontent.com/8c73c7cfae0d9fb6616ce8e32b31a5066efbc12989fbe1a7d81a755afb651d13/68747470733a2f2f706f7365722e707567782e6f72672f67616e676c696f2f706c656173652f6c6963656e7365)](https://packagist.org/packages/ganglio/Please)

Examples
--------

[](#examples)

Let's start with something simple:

```
$inverse = function ($v) {
  if (empty($v)) {
    throw new \Exception("Division by zero");
  }

  return 1/$v;
}
```

Usually what we would do is something like this:

```
try {
  $result = $inverse(0);
} catch (\Exception $e) {
  error_log("Error: " . $e->getMessage());
}
```

Using `Please` we do:

```
$result = new Please($inverse, 0);
```

Now we can check if the callable completed successfully or not.

```
if ($result->isSuccess) {
  echo "The result is: " . $result->get();
}
```

Or we can do it using a callback (much nicer)

```
$result->onSuccess(function ($v) {
  echo "The result is: " . $v;
});
```

Unfortunately we tried to divide by zero so the callable didn't succeeded. We can either get the exception:

```
$exception = $result->get();
```

Or process it with the callback:

```
$result->onFailure(function ($e) {
  error_log("Error: " . $e->getMessage());
});
```

We can even pass two callbacks using `on`:

```
$result->on(
  function ($v) {
    echo "Result: " . $v;
  },
  function ($e) {
    echo "Error: " . $e->getMessage();
  }
);
```

`onSuccess`, `onFailure` and `on` return a new instance of `Please` wrapping the callback. This way, if we want we can do something like this:

```
echo (new Please($inverse, $unknown_divisor))
  ->on(
    function ($v) {
      return "Result: " . $v;
    },
    function ($e) {
      return "Error: " . $e->getMessage;
    }
  )->get();
```

And now a slighly more complex example:

Let's immagine we have an array of strings, some of which are json encoded objects:

```
$strings = [
  'not json',
  '{"a":3,"b":4}',
  'still not json',
  '{"c":5}',
];
```

And a wrapper to `json_decode` throwing and exception on error:

```
$json_decoder_exception = function ($string) {
  $out = json_decode($string);
  if (json_last_error() != JSON_ERROR_NONE) {
    throw new \Exception("Invalid JSON");
  }
  return $out;
};
```

We can then decode and filter them using `Please`:

```
$results = array_filter(
  array_map(function ($s) use ($json_decoder_exception) {
    return new Please($json_decoder_exception, $s);
  }, $strings),
  function ($e) {
    return $e->isSuccess;
  }
);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

3724d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5305bcf3bda76fdc9179cd51aac78e79992208ad4414819a814c5d0c3315f75c?d=identicon)[ganglio](/maintainers/ganglio)

---

Top Contributors

[![ganglio](https://avatars.githubusercontent.com/u/498939?v=4)](https://github.com/ganglio "ganglio (5 commits)")

---

Tags

functionaltrycatch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ganglio-please/health.svg)

```
[![Health](https://phpackages.com/badges/ganglio-please/health.svg)](https://phpackages.com/packages/ganglio-please)
```

###  Alternatives

[lstrojny/functional-php

Functional primitives for PHP

2.0k7.3M48](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[lambdish/phunctional

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[crell/fp

Functional utilities for PHP 8 and later

91429.8k11](/packages/crell-fp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
