Skip to content

Commit

Permalink
Revert "[9.x] Allow using static closures as callable for macros (#43589
Browse files Browse the repository at this point in the history
)" (#43619)

This reverts commit 93090dc.
  • Loading branch information
taylorotwell committed Aug 9, 2022
1 parent 7094bc1 commit 477b656
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
11 changes: 1 addition & 10 deletions src/Illuminate/Macroable/Traits/Macroable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use BadMethodCallException;
use Closure;
use ReflectionClass;
use ReflectionFunction;
use ReflectionMethod;

trait Macroable
Expand Down Expand Up @@ -119,15 +118,7 @@ public function __call($method, $parameters)
$macro = static::$macros[$method];

if ($macro instanceof Closure) {
$reflection = new ReflectionFunction($macro);

$bindable = $reflection->getClosureScopeClass() === null || $reflection->getClosureThis() !== null;

if ($bindable) {
$macro = $macro->bindTo($this, static::class);
} else {
$macro = $macro->bindTo(null, static::class);
}
$macro = $macro->bindTo($this, static::class);
}

return $macro(...$parameters);
Expand Down
12 changes: 0 additions & 12 deletions tests/Support/SupportMacroableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ public function testClassBasedMacrosNoReplace()
$this->assertSame('foo', $instance->methodThree());
}

public function testSettingMacroUsingStaticClosures()
{
TestMacroable::macro('staticFn', static function () {
return 'I am unbound.';
});
TestMacroable::macro('speed', static fn () => 'I am speed.');
$instance = new TestMacroable;

$this->assertSame('I am unbound.', $instance->staticFn());
$this->assertSame('I am speed.', $instance->speed());
}

public function testFlushMacros()
{
TestMacroable::macro('flushMethod', function () {
Expand Down

0 comments on commit 477b656

Please sign in to comment.