diff --git a/Container.php b/Container.php index 0f2f299..280f4d8 100755 --- a/Container.php +++ b/Container.php @@ -648,7 +648,25 @@ public function wrap(Closure $callback, array $parameters = []) */ public function call($callback, array $parameters = [], $defaultMethod = null) { - return BoundMethod::call($this, $callback, $parameters, $defaultMethod); + $pushedToBuildStack = false; + + if (is_array($callback) && ! in_array( + $className = (is_string($callback[0]) ? $callback[0] : get_class($callback[0])), + $this->buildStack, + true + )) { + $this->buildStack[] = $className; + + $pushedToBuildStack = true; + } + + $result = BoundMethod::call($this, $callback, $parameters, $defaultMethod); + + if ($pushedToBuildStack) { + array_pop($this->buildStack); + } + + return $result; } /**