{"id":"a41085bfe95a69e8","repo":"laravel/framework","slug":"unable-to-bind-custom-driver-callback-a41085","errorCode":null,"errorMessage":"Unable to bind custom driver callback","messagePattern":"Unable to bind custom driver callback","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Broadcasting/BroadcastManager.php","lineNumber":512,"sourceCode":"        $name = enum_value($name) ?? $this->getDefaultDriver();\n\n        unset($this->drivers[$name]);\n    }\n\n    /**\n     * Register a custom driver creator Closure.\n     *\n     * @param  string  $driver\n     * @param  \\Closure  $callback\n     *\n     * @param-closure-this  $this  $callback\n     *\n     * @return $this\n     */\n    public function extend($driver, Closure $callback)\n    {\n        try {\n            $callback = $this->bindCallbackToSelf($callback) ?? throw new RuntimeException('Unable to bind custom driver callback');\n        } catch (ReflectionException $e) {\n            throw new RuntimeException('Unable to bind custom driver callback', previous: $e);\n        }\n\n        $this->customCreators[$driver] = $callback;\n\n        return $this;\n    }\n\n    /**\n     * Execute the given callback using \"rescue\" if possible.\n     *\n     * @param  \\Closure  $callback\n     * @return mixed\n     */\n    protected function rescue(Closure $callback)\n    {\n        if (function_exists('rescue')) {","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Broadcasting/BroadcastManager.php#L494-L530","documentation":"Thrown by BroadcastManager::extend() when bindCallbackToSelf() returns null. bindCallbackToSelf calls Closure::bindTo() on anonymous closures and returns null if rebinding failed, so the manager refuses to register a broken creator.","triggerScenarios":"Calling Broadcast::extend('driver', $callback) with an anonymous closure whose Closure::bindTo() cannot bind it to the BroadcastManager scope (e.g., a static closure that cannot be re-scoped).","commonSituations":"Rare; passing a static anonymous closure or a closure with incompatible bound scope as a broadcast driver creator.","solutions":["Pass a regular (non-static) Closure so it can be rebound to the manager.","Use an invokable class instance as the creator instead of an anonymous closure.","Avoid Closure::fromCallable over internal functions for the creator."],"exampleFix":"// before\nBroadcast::extend('custom', static function ($app, $config) {\n    return new CustomBroadcaster($config);\n});\n\n// after\nBroadcast::extend('custom', function ($app, $config) {\n    return new CustomBroadcaster($config);\n});","handlingStrategy":"validation","validationCode":"$callback = function ($app, $config) { /* ... */ };\n$rebound = $callback->bindTo(app(BroadcastManager::class), BroadcastManager::class);\nif ($rebound === null) {\n    throw new RuntimeException('Closure cannot be rebound; use a non-static closure.');\n}\nBroadcast::extend('custom', $callback);","typeGuard":"function isRebindableBroadcastClosure(\\Closure $c, object $scope): bool\n{\n    try {\n        return (new \\ReflectionFunction($c))->isAnonymous()\n            ? $c->bindTo($scope, $scope::class) !== null\n            : true;\n    } catch (\\ReflectionException) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    Broadcast::extend('custom', $callback);\n} catch (\\RuntimeException $e) {\n    Broadcast::extend('custom', app(CustomBroadcasterFactory::class));\n}","preventionTips":["Avoid static anonymous closures as broadcast driver creators.","Prefer invokable class instances over anonymous closures.","Unit-test driver registration right after defining it."],"tags":["broadcasting","extension","closure","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}