Created
August 15, 2011 11:04
-
-
Save sunaot/1146041 to your computer and use it in GitHub Desktop.
Accessing static private variable hack using closure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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