PHPackages                             originphp/defer - 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. originphp/defer

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

originphp/defer
===============

OriginPHP Defer - PHP implementation of the Go language defer statement

3.0.0(5y ago)218.5k↑837.5%7MITPHPPHP &gt;=7.3.0

Since Oct 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/originphp/defer)[ Packagist](https://packagist.org/packages/originphp/defer)[ Docs](https://www.originphp.com)[ RSS](/packages/originphp-defer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (7)Used By (7)

Defer
=====

[](#defer)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/originphp/defer/workflows/CI/badge.svg)](https://github.com/originphp/defer/actions)[![coverage](https://camo.githubusercontent.com/fb2ce974b0edae8d6e8c3682530ee2a401c1e38c51e3b0d1717ac42c90be14eb/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f726967696e7068702f64656665722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/originphp/defer?branch=master)

Defer the execution of a function until the surrounding function completes based upon the Go language defer function. Calls are executed in Last In First Out. Defer is usually used for cleanup operations such as closing or unlocking files, even if there is an error.

Installation
------------

[](#installation)

To install this package

```
$ composer require originphp/defer

```

Usage
-----

[](#usage)

> As of version 3.0 the defer function has been moved to its own namespace to prevent clashing with other libraries and PHP extensions.

To defer the execution of a function until the surrounding function completes, calls are executed in Last In First Out order.

```
use function Origin\Defer\defer;

public function doSomething()
{
    $fileHandle = fopen($this->filename, 'rt');
    defer($queue, 'fclose', $fileHandle);
    ...
    return $result;
}
```

Or

```
use function Origin\Defer\defer;
defer($var,[$this,'method']);
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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

Recently: every ~43 days

Total

6

Last Release

1852d ago

Major Versions

1.0.1 → 2.0.02021-01-03

2.0.2 → 3.0.02021-04-13

PHP version history (3 changes)1.0.0PHP ^7.2.0

1.0.1PHP &gt;=7.2.0

2.0.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e8a821333d9c7b7bc2ad3d164d142f65cd3912dea78033d31f76b0f19ba8a0c?d=identicon)[originphp](/maintainers/originphp)

---

Top Contributors

[![jamielsharief](https://avatars.githubusercontent.com/u/20553479?v=4)](https://github.com/jamielsharief "jamielsharief (30 commits)")

---

Tags

originPHP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/originphp-defer/health.svg)

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

###  Alternatives

[magepow/categories

Shows categories in the form of a grid or list, on category pages, home page or any other page.

4018.8k](/packages/magepow-categories)

PHPackages © 2026

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