Skip to content

Commit f3b4512

Browse files
committed
Rebind $this for static closure macros
1 parent 11b6941 commit f3b4512

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Illuminate/Support/Traits/Macroable.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Closure;
66
use ReflectionClass;
77
use ReflectionMethod;
8+
use ReflectionFunction;
89
use BadMethodCallException;
910

1011
trait Macroable
@@ -80,11 +81,15 @@ public static function __callStatic($method, $parameters)
8081
));
8182
}
8283

83-
if (static::$macros[$method] instanceof Closure) {
84-
return call_user_func_array(Closure::bind(static::$macros[$method], null, static::class), $parameters);
84+
$macro = static::$macros[$method];
85+
86+
if ($macro instanceof Closure) {
87+
$newThis = (new ReflectionFunction($macro))->getClosureThis();
88+
89+
return call_user_func_array($macro->bindTo($newThis), $parameters);
8590
}
8691

87-
return call_user_func_array(static::$macros[$method], $parameters);
92+
return call_user_func_array($macro, $parameters);
8893
}
8994

9095
/**

0 commit comments

Comments
 (0)