{"record":{"id":"a51c4b6a8ec89a68","repo":"ramsey/uuid","slug":"s-argument-1-data-is-invalid-a51c4b","errorCode":null,"errorMessage":"%s(): Argument #1 ($data) is invalid","messagePattern":"(.+?)\\(\\): Argument #1 \\(\\$data\\) is invalid","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/Type/Decimal.php","lineNumber":119,"sourceCode":"\n    /**\n     * Constructs the object from a serialized string representation\n     *\n     * @param string $data The serialized string representation of the object\n     */\n    public function unserialize(string $data): void\n    {\n        $this->__construct($data);\n    }\n\n    /**\n     * @param array{string?: string} $data\n     */\n    public function __unserialize(array $data): void\n    {\n        // @codeCoverageIgnoreStart\n        if (!isset($data['string'])) {\n            throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));\n        }\n        // @codeCoverageIgnoreEnd\n\n        $this->unserialize($data['string']);\n    }\n}\n","sourceCodeStart":101,"sourceCodeEnd":126,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Type/Decimal.php#L101-L126","documentation":"When PHP unserializes a Ramsey\\Uuid\\Type\\Decimal object, __unserialize(array $data) runs and requires the array key 'string' (the shape produced by __serialize()). If the payload lacks that key, a native ValueError is thrown with a message mimicking PHP's internal argument errors. This indicates the serialized payload does not match the class's expected serialization shape — corrupted data, hand-crafted payloads, or a different format written by other code.","triggerScenarios":"unserialize() of a stored/cached Decimal payload whose array body lacks 'string' — e.g. hand-assembled serialized strings, cache entries written by a different serialization scheme, or partial payloads returned after unserialize() with allowed_classes restrictions reshapes data.","commonSituations":"Redis/session/cache values written by an older application version or a different library; corrupted cache after crashes; cross-system payload exchange where the producer serializes a different array shape; tests feeding literal serialized strings.","solutions":["Stop unserializing the stale payload and rebuild the object: $decimal = new Decimal($rawString)","Invalidate/flush the cache or session entries holding the malformed payloads","Ensure every environment that reads the cache runs a compatible version of the code that wrote it","Prefer storing scalar values (the decimal string) and constructing Decimal on read instead of serializing objects"],"exampleFix":"// before\n$decimal = unserialize($cachedValue); // payload missing the 'string' key\n// ValueError: Ramsey\\Uuid\\Type\\Decimal::__unserialize(): Argument #1 ($data) is invalid\n\n// after: cache the scalar and rebuild the value object on read\n$decimal = new Decimal($cachedValue); // $cachedValue = '1234.50'","handlingStrategy":"try-catch","validationCode":"// Validate the payload shape before trusting it, then reconstruct\n$decoded = unserialize($cached, ['allowed_classes' => false]);\nif (!is_string($decoded) && !(is_array($decoded) && isset($decoded['string']))) {\n    // treat as cache miss and rebuild\n    $decimal = new Decimal($fallbackValue);\n}","typeGuard":null,"tryCatchPattern":"use Ramsey\\Uuid\\Type\\Decimal;\n\ntry {\n    $decimal = unserialize($cached);\n} catch (\\ValueError $e) {\n    // malformed payload: treat as a cache miss and rebuild\n    $decimal = new Decimal($freshValue);\n}","preventionTips":["Cache the scalar decimal string, not the serialized object","Version cache keys so format changes do not read stale shapes","Pin compatible library versions across environments sharing the cache","Wrap unserialize() of stored data in try-catch with a rebuild path"],"tags":["php","ramsey-uuid","decimal","unserialize","value-error","cache-corruption"],"backgroundTag":"unserialize-payload-invalid","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}