Hello! When I use a static anonymous function as an HTTP-action in
some frameworks like:

$app = new App();
$app->get('/', static function () {
   return new Response('Hello!);
})

I get a warning "Cannot bind an instance to a static closure" in every
$closure->bind($container) call inside of the framework.

But right now I cannot prevent this warning because there is no native
way to check that closure is static before calling the bind method. I
can only suppress the warning with @ or set/restore_error_handler
pair.

So I propose to add a method like Closure::isStatic (or
Closure::canBeBound, etc.) for ability of manual checking it before
bind call:

if (!$closure->isStatic()) {
   $closure->bind($object);
}

The method can contain simple statement:

return func->common.fn_flags & ZEND_ACC_STATIC;

It will be helpful if somebody needs to support dynamic and static
callables both without warnings.

-- Best, Dmitry

Reply via email to