Skip to content

Commit

Permalink
[9.x] Fix bound method contextual binding (#45500)
Browse files Browse the repository at this point in the history
* fix method contextual binding

* fix styling

* formatting and fixes for static methods

* add test

* improve test

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
imdhemy and taylorotwell authored Jan 5, 2023
1 parent 8ca3036 commit 62d43e0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 62d43e0

Please sign in to comment.