Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunaot/1146041 to your computer and use it in GitHub Desktop.
Save sunaot/1146041 to your computer and use it in GitHub Desktop.
Accessing static private variable hack using closure.
<?php
class Sample
{
static private $value = 0;
static function privateHack() {
$hack =& static::$value;
return function($val) use (&$hack) {
$hack = $val;
};
}
static function show() {
echo static::$value;
}
}
$hack = Sample::privateHack();
$hack(10);
Sample::show(); // => 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment