victorwesterlund / globalsnapshot
Capture and restore the state of all PHP superglobals.
Installs: 33
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/victorwesterlund/globalsnapshot
This package is auto-updated.
Last update: 2024-11-23 09:28:22 UTC
README
Capture the current state of all PHP superglobal variables; which can then be restored to that state at a later time.
Example use:
// 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"
Quickstart
- Install with composer
composer install victorwesterlund/globalsnapshot
usein your project
use victorwesterlund\GlobalSnapshot;
- Capture current superglobals with
capture()
// Initialize a new GlobalSnapshot instance to store current values (one snapshot per instance) $snapshot = new GlobalSnapshot(); // Capture current superglobal state $snapshot->capture();
- Restore superglobals with
restore()
// ... some other code // Restore superglobals to state of `capture()` $snapshot->restore();