Created
May 11, 2014 17:28
-
-
Save KAYLukas/0b1d65e57b52862f8da5 to your computer and use it in GitHub Desktop.
This file contains 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
class Mock{ | |
private $context; | |
public function __construct($a){ | |
$this->context = new Context($a); | |
} | |
public function __destruct(){ | |
Context::destroyContext($this->context); | |
} | |
} | |
class Context { | |
public $a; | |
public static $ref = []; | |
public function __construct($a){ | |
$this->a = $a; | |
array_push(self::$ref, $this); | |
} | |
public function destroyContext($context){ | |
self::$ref = array_filter(self::$ref, function($ref) use ($context){ return $context !== $ref;}); | |
} | |
public static function getCurrentContext(){ | |
return end(self::$ref); | |
} | |
} | |
function x($i){ | |
$a = new Mock($i); | |
var_dump(Context::getCurrentContext()); | |
if($i < 100){ | |
x($i + 1); | |
} | |
var_dump(Context::getCurrentContext()); | |
} | |
x(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment