phplang/scope-exit
最新稳定版本:1.0.0
Composer 安装命令:
composer require phplang/scope-exit
包简介
Emulation of SCOPE_EXIT construct from C++
README 文档
README
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)
统计信息
- 总下载量: 11.6M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: BSD
- 更新时间: 2026-01-04