Slim: DeferredCallable cannot accept static closures

DeferredCallable makes the (invalid) assumption that any Closure can be bound to an instance of an object. Clearly this is false for static closures since they are unbound by definition.

The following code will generate a “Cannot bind an instance to a static closure” warning once the framework begins processing a request.

(new Slim\App)->add(static function () {})->process(...);

Slim should not attempt to bind to static closures.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 28 (26 by maintainers)

Most upvoted comments

@adriansuter since static methods cannot be bound I would suggest against it. We should deny static handlers across the board. I think we need to distinctively draw a line here otherwise it gets confusing. I’m not a fan of using reflections to achieve things, it feels forced.

/* ignore errors */ ⬅️ 😱

As you made clear, there is no need for static closures. If someone doesn’t want binding, use a class.

@adriansuter the reason why someone would try to use a static closure is probably to control its binding (so it doesn’t get autobound) or in case they would try to “optimize” performance while it is an unnoticeable increase.

I am equally good with @shadowhand’s view that we don’t support static anonymous functions.