laravel/framework · error · RuntimeException

Unable to bind custom driver callback

Error message

Unable to bind custom driver callback

What it means

Thrown by BroadcastManager::extend() on the null-coalesce-throw line when bindCallbackToSelf($callback) returns null. extend() rebinds the supplied Closure so $this inside it refers to the BroadcastManager; if the rebinder cannot produce a bound closure it throws this RuntimeException. This is the null-return branch, distinct from the ReflectionException branch on the next line.

Solutions

  1. Pass a non-static closure so it can be rebound to the BroadcastManager instance.
  2. If the logic must not capture $this, restructure into an invokable class instantiated explicitly.
  3. Ensure the closure is a genuine Closure object, not a stripped scope.
  4. Verify PHP version compatibility for Closure::bind behavior.

Example fix

// before — static closure cannot be rebound
Broadcast::extend('websocket', static function ($app, array $config) {
    return new WebsocketBroadcaster($config);
});

// after — non-static closure
Broadcast::extend('websocket', function ($app, array $config) {
    return new WebsocketBroadcaster($config);
});
Defensive patterns

Strategy: validation

Validate before calling

// PHP — ensure the closure is non-static before extend()
$ref = new \ReflectionFunction($callback);
if ($ref->isStatic()) {
    throw new \RuntimeException('Cannot Broadcast::extend() with a static closure; use a non-static closure.');
}
Broadcast::extend($driver, $callback);

Type guard

function isRebindableClosure(\Closure $c): bool {
    return ! (new \ReflectionFunction($c))->isStatic();
}

Try / catch

try {
    Broadcast::extend($driver, $callback);
} catch (\RuntimeException $e) {
    Log::error('Broadcast::extend failed to bind', ['driver' => $driver, 'err' => $e->getMessage()]);
    throw $e;
}

Prevention

When it happens

Trigger: Calling Broadcast::extend($driver, $callback) with a closure that bindCallbackToSelf cannot rebind (returns null) — most commonly a static closure, since Closure::bind returns null when binding a static closure to an instance scope.

Common situations: Registering a custom broadcaster with static fn (...); first-class callable syntax producing a closure whose scope cannot be rebound; PHP version differences affecting Closure::bind for static closures.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/a41085bfe95a69e8. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Broadcasting/BroadcastManager.php:512

        $name = enum_value($name) ?? $this->getDefaultDriver();

        unset($this->drivers[$name]);
    }

    /**
     * Register a custom driver creator Closure.
     *
     * @param  string  $driver
     * @param  \Closure  $callback
     *
     * @param-closure-this  $this  $callback
     *
     * @return $this
     */
    public function extend($driver, Closure $callback)
    {
        try {
            $callback = $this->bindCallbackToSelf($callback) ?? throw new RuntimeException('Unable to bind custom driver callback');
        } catch (ReflectionException $e) {
            throw new RuntimeException('Unable to bind custom driver callback', previous: $e);
        }

        $this->customCreators[$driver] = $callback;

        return $this;
    }

    /**
     * Execute the given callback using "rescue" if possible.
     *
     * @param  \Closure  $callback
     * @return mixed
     */
    protected function rescue(Closure $callback)
    {
        if (function_exists('rescue')) {

View on GitHub (pinned to e0f6eb3518)