{"record":{"id":"2cbe6970019e245c","repo":"ratchetphp/Ratchet","slug":"argument-3-loop-expected-null-react-eventloop-loopinterface","errorCode":null,"errorMessage":"Argument #3 ($loop) expected null|React\\EventLoop\\LoopInterface","messagePattern":"Argument #3 \\(\\$loop\\) expected null\\|React\\\\EventLoop\\\\LoopInterface","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Ratchet/Server/IoServer.php","lineNumber":40,"sourceCode":"    /**\n     * @var \\Ratchet\\MessageComponentInterface\n     */\n    public $app;\n\n    /**\n     * The socket server the Ratchet Application is run off of\n     * @var \\React\\Socket\\ServerInterface\n     */\n    public $socket;\n\n    /**\n     * @param \\Ratchet\\MessageComponentInterface  $app      The Ratchet application stack to host\n     * @param \\React\\Socket\\ServerInterface       $socket   The React socket server to run the Ratchet application off of\n     * @param \\React\\EventLoop\\LoopInterface|null $loop     The React looper to run the Ratchet application off of\n     */\n    public function __construct(MessageComponentInterface $app, ServerInterface $socket, $loop = null) {\n        if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1\n            throw new \\InvalidArgumentException('Argument #3 ($loop) expected null|React\\EventLoop\\LoopInterface');\n        }\n\n        if (false === strpos(PHP_VERSION, \"hiphop\")) {\n            gc_enable();\n        }\n\n        set_time_limit(0);\n        ob_implicit_flush();\n\n        $this->loop = $loop;\n        $this->app  = $app;\n        $this->socket = $socket;\n\n        $socket->on('connection', array($this, 'handleConnect'));\n    }\n\n    /**\n     * @param  \\Ratchet\\MessageComponentInterface $component  The application that I/O will call when events are received","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/ratchetphp/Ratchet/blob/e621c6c40bf684bbbb877102416ad5303d05a9cc/src/Ratchet/Server/IoServer.php#L22-L58","documentation":"This is an argument type/count validation error raised in IoServer::__construct() when the third argument ($loop) is not null and not an instance of React\\EventLoop\\LoopInterface. IoServer requires a loop either injected directly or, when null, one resolved later via factory()/run(); passing any other value (e.g. a string, a closed loop of the wrong type, or an extra positional argument) means the server cannot be constructed.","triggerScenarios":"Thrown at src/Ratchet/Server/IoServer.php:40 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an instance of React\\EventLoop\\LoopInterface (e.g. React\\EventLoop\\Loop::get() on event-loop v1.2+, or Factory::create() on older versions) as the third argument.","Pass explicit null as $loop if you intend the server to use a default loop resolved internally.","Check the call site for argument order — the loop must come after $app and $socket, and no additional arguments should be passed."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e621c6c40bf684bbbb877102416ad5303d05a9cc","analyzedAt":"2026-09-16T00:13:27.878Z","contentChangedAt":"2026-09-16T00:13:27.878Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}