diff --git a/src/DelegatingContainer.php b/src/DelegatingContainer.php index 2690f1d..fa5da2c 100644 --- a/src/DelegatingContainer.php +++ b/src/DelegatingContainer.php @@ -26,6 +26,12 @@ class DelegatingContainer implements ContainerInterface */ protected $parent; + /** + * Keys represent the list of service names accessed recursively, in order of access + * @var array + */ + protected $stack = []; + /** */ public function __construct(ServiceProviderInterface $provider, PsrContainerInterface $parent = null) @@ -39,10 +45,8 @@ public function __construct(ServiceProviderInterface $provider, PsrContainerInte */ public function get($id) { - static $stack = []; - - if (array_key_exists($id, $stack)) { - $trace = implode(' -> ', array_keys($stack)) . ' -> ' . $id; + if (array_key_exists($id, $this->stack)) { + $trace = implode(' -> ', array_keys($this->stack)) . ' -> ' . $id; throw new ContainerException( $this->__("Circular dependency detected:\n%s", [$trace]), @@ -51,12 +55,12 @@ public function get($id) ); } - $stack[$id] = true; + $this->stack[$id] = true; try { return $this->createService($id); } finally { - unset($stack[$id]); + unset($this->stack[$id]); } }