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

ActiveLibrary

icio/scope
==========

0.4(11y ago)1211MITPHP

Since Sep 15Pushed 11y ago2 watchersCompare

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

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

Scope [![Build Status](https://camo.githubusercontent.com/e2a15a306d120675548fd6621cab3cdb3b9229b16464e306e569816d38f08772/68747470733a2f2f7472617669732d63692e6f72672f6963696f2f73636f70652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/icio/scope)
===================================================================================================================================================================================================================================================================

[](#scope-)

Scope offers a mechanism for preparing global environments and containers for the duration of a callback, keeping state mutation and clean-up to only declaration in your code. Inspired by Python's native [with](https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers).

For example, instead of doing:

```
global $x;
$xBackup = $x;
$x = $xNew;
$done = do_it();
$x = $xBackup;
```

with `KeyState` you can set an Array key state:

```
(new KeyState($GLOBALS, array("x" => $newX)))->call('do_it');
```

Currently available scopes help with:

- Collecting multiple scopes together, with `Scope`;
- Setting temporary values on arrays, with `KeyState`;
- Capturing function output, with `Buffer`;
- Changing into a new directory, with `WorkingDirectory`; and
- Worrying about different error levels, with `ErrorReporting`.

Sometimes you'll want to hop in and out of a given scope, providing default context by following the changes incurred by your actions within. The scopes can optionally account for this. The `Buffer` can collect the output across multiple sessions; the `WorkingDirectory` can go back to the directory it left upon re-entry; the `KetState` can track the value of keys, should they be changed in-scope; and the `ErrorReporting` can track any changes to the reporting. See the spec tests for details.

All entered scopes are passed into the callback as function arguments. For example, when working with output buffers you can capture and return the output as so:

```
$output = (new Scope(
    new Buffer(Buffer::CLEAN),
    new WorkingDirectory("./old")
))->call(function(Buffer $buffer) {
    require "old-script.php";
    return $buffer->getContents();
});
```

If exceptions are thrown during the callback then we close the scopes and re-throw the exception. If exceptions are thrown by the scopes then we clean up any already entered and re-throw the exception. Exceptions thrown whilst trying to leave a scope prevent the clean-up of others (which should perhaps change).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

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

Total

2

Last Release

4251d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b7e19f5e52ac8316e506370eec3770169a6e8fff8fc3c8c317b7597425ae7b5?d=identicon)[icio](/maintainers/icio)

---

Top Contributors

[![icio](https://avatars.githubusercontent.com/u/408401?v=4)](https://github.com/icio "icio (15 commits)")

### Embed Badge

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

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

PHPackages © 2026

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