VictorWesterlund / globalsnapshot
捕获并恢复所有PHP超级全局变量的状态。
1.0.2
2024-04-19 09:43 UTC
This package is auto-updated.
Last update: 2024-09-19 10:32:54 UTC
README
捕获所有当前 PHP 超级全局变量 的状态;然后在稍后时间恢复到该状态。
示例用法
// Initial state $_ENV["hello"] = "world"; // echo: "world" // Capture initial state $snapshot = (new GlobalSnapshot())->capture(); // Manipulate superglobals $_ENV["hello"] .= " and mom!"; // echo: "world and mom" // Restore initial state $snapshot->restore(); // Initial state restored echo $_ENV["hello"]; // echo: "world"
快速开始
- 使用composer安装
composer install victorwesterlund/globalsnapshot
- 在项目中使用
use
use victorwesterlund\GlobalSnapshot;
- 使用
capture()
捕获当前超级全局变量
// Initialize a new GlobalSnapshot instance to store current values (one snapshot per instance) $snapshot = new GlobalSnapshot(); // Capture current superglobal state $snapshot->capture();
- 使用
restore()
恢复超级全局变量
// ... some other code // Restore superglobals to state of `capture()` $snapshot->restore();