Skip to content

Capture and restore the current state of all PHP superglobals.

License

Notifications You must be signed in to change notification settings

VictorWesterlund/php-globalsnapshot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-globalsnapshot

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

  1. Install with composer
composer install victorwesterlund/globalsnapshot
  1. use in your project
use victorwesterlund\GlobalSnapshot;
  1. 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();
  1. Restore superglobals with restore()
// ... some other code

// Restore superglobals to state of `capture()`
$snapshot->restore();

About

Capture and restore the current state of all PHP superglobals.

Resources

License

Stars

Watchers

Forks

Languages