PHPackages                             phplang/scope-exit - 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. phplang/scope-exit

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

phplang/scope-exit
==================

Emulation of SCOPE\_EXIT construct from C++

1.0.0(9y ago)1913.0M↓44.5%3[1 PRs](https://github.com/phplang/scope-exit/pulls)4BSDPHP

Since Sep 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/phplang/scope-exit)[ Packagist](https://packagist.org/packages/phplang/scope-exit)[ Docs](https://github.com/phplang/scope-exit)[ RSS](/packages/phplang-scope-exit/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (4)

ScopeExit
=========

[](#scopeexit)

This simple class provides an implementation of C++'s `SCOPE_EXIT`, or GoLang's `defer`.

To use, assign an instance of this object to a local variable. When that variable falls out of scope (or is explicitly `unset`), the callback passed to the constructor will be invoked. This is useful, for example, to aid cleanup at the end of a function.

```
function f(&$x) {
  $x = 1;
  $_ = new \PhpLang\ScopeExit(function() use (&$x) { $x = 2; });
  // $x is still 1 at this point.
  return 42;
  // After the return, the local scope is cleaned up, the closure is invoked, and it's set to 2
}

f($a);
var_dump($a); // int(2)
```

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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

Unknown

Total

1

Last Release

3553d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e7fd24eebfcbd0e9753a50a5ab51c025295665081e35addb79bc2cd7f93fa0d?d=identicon)[sgolemon](/maintainers/sgolemon)

---

Top Contributors

[![sgolemon](https://avatars.githubusercontent.com/u/812538?v=4)](https://github.com/sgolemon "sgolemon (3 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (1 commits)")[![simonwelsh](https://avatars.githubusercontent.com/u/125915?v=4)](https://github.com/simonwelsh "simonwelsh (1 commits)")

---

Tags

scopecleanupexit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phplang-scope-exit/health.svg)

```
[![Health](https://phpackages.com/badges/phplang-scope-exit/health.svg)](https://phpackages.com/packages/phplang-scope-exit)
```

###  Alternatives

[liborm85/composer-vendor-cleaner

Composer Vendor Cleaner removes unnecessary development files and directories from vendor directory.

35389.0k1](/packages/liborm85-composer-vendor-cleaner)[tarunkorat/laravel-asset-cleaner

Safely detect and remove unused CSS, JS, SCSS and other assets from Laravel applications

745.0k1](/packages/tarunkorat-laravel-asset-cleaner)[goszowski/laravel-vendor-minify

A vendor minify package, to remove tests and documentation and minifing all php files to save space

803.6k](/packages/goszowski-laravel-vendor-minify)[wapplersystems/core-upgrader

Run upgrade wizards for multiple TYPO3 versions at once and clean up the system

1026.0k1](/packages/wapplersystems-core-upgrader)[aura/includer

Include multiple files from specified directories, in order, with variables extracted into a limited include scope.

133.2k](/packages/aura-includer)

PHPackages © 2026

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