2017 © Pedro Peláez
 

library scope-exit

Emulation of SCOPE_EXIT construct from C++

image

phplang/scope-exit

Emulation of SCOPE_EXIT construct from C++

  • Saturday, September 17, 2016
  • by sgolemon
  • Repository
  • 1 Watchers
  • 7 Stars
  • 14,796 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 280 % Grown

The README.md

ScopeExit

This simple class provides an implementation of C++'s SCOPE_EXIT, or GoLang's defer., (*1)

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., (*2)

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)

The Versions

17/09 2016

dev-master

9999999-dev https://github.com/phplang/scope-exit

Emulation of SCOPE_EXIT construct from C++

  Sources   Download

BSD

The Development Requires

cleanup scope exit

17/09 2016

1.0.0

1.0.0.0 https://github.com/phplang/scope-exit

Emulation of SCOPE_EXIT construct from C++

  Sources   Download

BSD

The Development Requires

cleanup scope exit