{"record":{"id":"a5e38a7385e14b5e","repo":"ratchetphp/Ratchet","slug":"invalid-data-remaining","errorCode":null,"errorMessage":"invalid data, remaining: ","messagePattern":"invalid data, remaining: ","errorType":"exception","errorClass":"UnexpectedValueException","httpStatus":null,"severity":"error","filePath":"src/Ratchet/Session/Serialize/PhpHandler.php","lineNumber":34,"sourceCode":"            }\n            $serialized = implode('', $preSerialized);\n        }\n\n        return $serialized;\n    }\n\n    /**\n     * {@inheritdoc}\n     * @link http://ca2.php.net/manual/en/function.session-decode.php#108037 Code from this comment on php.net\n     * @throws \\UnexpectedValueException If there is a problem parsing the data\n     */\n    public function unserialize($raw) {\n        $returnData = array();\n        $offset     = 0;\n\n        while ($offset < strlen($raw)) {\n            if (!strstr(substr($raw, $offset), \"|\")) {\n                throw new \\UnexpectedValueException(\"invalid data, remaining: \" . substr($raw, $offset));\n            }\n\n            $pos     = strpos($raw, \"|\", $offset);\n            $num     = $pos - $offset;\n            $varname = substr($raw, $offset, $num);\n            $offset += $num + 1;\n\n            // try to unserialize one piece of data from current offset, ignoring any warnings for trailing data on PHP 8.3+\n            // @link https://wiki.php.net/rfc/unserialize_warn_on_trailing_data\n            $data = @unserialize(substr($raw, $offset));\n\n            $returnData[$varname] = $data;\n            $offset += strlen(serialize($data));\n        }\n\n        return $returnData;\n    }\n}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/ratchetphp/Ratchet/blob/e621c6c40bf684bbbb877102416ad5303d05a9cc/src/Ratchet/Session/Serialize/PhpHandler.php#L16-L52","documentation":"PhpHandler::unserialize() decodes a 'php'-serialized session string, which requires every key to be delimited from its value by a '|' character. This \\UnexpectedValueException fires when, at the current parse offset, no '|' remains in the remaining raw data — meaning the session payload is truncated, corrupted, or was not produced with the 'php' serialize_handler (e.g. php_serialized or php_binary format). The malformed segment cannot be mapped to a key/value pair, so parsing aborts with the leftover data reported in the message.","triggerScenarios":"Thrown at src/Ratchet/Session/Serialize/PhpHandler.php:34 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the session data was encoded with the same handler: encode with PhpHandler::serialize() and the ini setting session.serialize_handler=php before decoding.","Inspect the raw payload for truncation or corruption (missing '|' delimiters), e.g. log it, and discard/regenerate the session when it is invalid.","Wrap unserialize() in a try/catch for \\UnexpectedValueException and treat it as an expired/invalid session: clear the data and start a fresh session instead of failing the request."],"exampleFix":null,"handlingStrategy":"validation","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"}