PHPackages                             wikimedia/scoped-callback - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wikimedia/scoped-callback

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wikimedia/scoped-callback
=========================

Make a callback run when a dummy object leaves the scope.

v5.0.0(1y ago)4869.5k↓33.6%7GPL-2.0-or-laterPHPPHP &gt;=7.4

Since Sep 29Pushed 1mo ago8 watchersCompare

[ Source](https://github.com/wikimedia/mediawiki-libs-ScopedCallback)[ Packagist](https://packagist.org/packages/wikimedia/scoped-callback)[ Docs](https://www.mediawiki.org/wiki/ScopedCallback)[ RSS](/packages/wikimedia-scoped-callback/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (7)Versions (6)Used By (7)

[![Latest Stable Version](https://camo.githubusercontent.com/664cb918e1fdd1e431a4b10065a7b10730b8f87a923fdb414f1021794ae0ef91/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f73636f7065642d63616c6c6261636b2f762f737461626c652e737667)](https://packagist.org/packages/wikimedia/scoped-callback) [![License](https://camo.githubusercontent.com/2b8e50250dec6a3017c8643feb73d42854fcd1fc04fb413870bb746e4f6da664/68747470733a2f2f706f7365722e707567782e6f72672f77696b696d656469612f73636f7065642d63616c6c6261636b2f6c6963656e73652e737667)](https://packagist.org/packages/wikimedia/scoped-callback)

ScopedCallback
==============

[](#scopedcallback)

The ScopedCallback class allows for running a function after the instance goes out of scope. It can be useful for making sure teardown or cleanup functions run even if exceptions are thrown. It also makes for a cleaner API for developers, by not requiring the callback to be called manually each time.

Additional documentation about the library can be found on [MediaWiki.org](https://www.mediawiki.org/wiki/ScopedCallback).

Usage
-----

[](#usage)

```
use Wikimedia\ScopedCallback;
$sc = new ScopedCallback( [ $this, 'teardown' ] );
// Even if this throws an exception, the callback will run
// or it'll run at the end of the function
$this->fooBar();
// If you want to manually call the callback
ScopedCallback::consume( $sc );
// or
unset( $sc );
// If you want to prevent it from being called
ScopedCallback::cancel( $sc );
```

Running tests
-------------

[](#running-tests)

```
composer install --prefer-dist
composer test

```

---

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance68

Regular maintenance activity

Popularity41

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~737 days

Total

5

Last Release

588d ago

Major Versions

v1.0.0 → v2.0.02018-05-09

v2.0.0 → v3.0.02018-10-30

v3.0.0 → v4.0.02022-07-08

v4.0.0 → v5.0.02024-10-29

PHP version history (4 changes)v1.0.0PHP &gt;=5.5.9

v3.0.0PHP &gt;=5.6.99

v4.0.0PHP &gt;=7.2.9

v5.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b94d9718c06ec7c3fd7a104bc44966fb7464b9ec7411582343ea35a7a6a85f08?d=identicon)[mediawiki](/maintainers/mediawiki)

![](https://www.gravatar.com/avatar/716c86d71cbf921e7912a505f89d799de398fc0a3af0bd4c8862834b2d642bd7?d=identicon)[wikimedia](/maintainers/wikimedia)

---

Top Contributors

[![jdforrester](https://avatars.githubusercontent.com/u/881572?v=4)](https://github.com/jdforrester "jdforrester (13 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (12 commits)")[![legoktm](https://avatars.githubusercontent.com/u/81392?v=4)](https://github.com/legoktm "legoktm (8 commits)")[![reedy](https://avatars.githubusercontent.com/u/67615?v=4)](https://github.com/reedy "reedy (5 commits)")[![MatmaRex](https://avatars.githubusercontent.com/u/160413?v=4)](https://github.com/MatmaRex "MatmaRex (4 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (1 commits)")[![StevenJW](https://avatars.githubusercontent.com/u/10002591?v=4)](https://github.com/StevenJW "StevenJW (1 commits)")[![tstarling](https://avatars.githubusercontent.com/u/389141?v=4)](https://github.com/tstarling "tstarling (1 commits)")[![FlorianSW](https://avatars.githubusercontent.com/u/4892966?v=4)](https://github.com/FlorianSW "FlorianSW (1 commits)")[![DannyS712](https://avatars.githubusercontent.com/u/46829944?v=4)](https://github.com/DannyS712 "DannyS712 (1 commits)")[![Krinkle](https://avatars.githubusercontent.com/u/156867?v=4)](https://github.com/Krinkle "Krinkle (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikimedia-scoped-callback/health.svg)

```
[![Health](https://phpackages.com/badges/wikimedia-scoped-callback/health.svg)](https://phpackages.com/packages/wikimedia-scoped-callback)
```

###  Alternatives

[hexadog/laravel-theme-installer

1040.8k4](/packages/hexadog-laravel-theme-installer)

PHPackages © 2026

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