{"record":{"id":"75e3db111fbe7361","repo":"ramsey/uuid","slug":"s-argument-1-data-is-invalid-75e3db","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/Hexadecimal.php","lineNumber":106,"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    /**\n     * @return non-empty-string\n     */\n    private function prepareValue(string $value): string\n    {\n        $value = strtolower($value);\n\n        if (str_starts_with($value, '0x')) {\n            $value = substr($value, 2);\n        }\n\n        if (!preg_match('/^[A-Fa-f0-9]+$/', $value)) {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Type/Hexadecimal.php#L88-L124","documentation":"When PHP unserializes a Ramsey\\Uuid\\Type\\Hexadecimal object, __unserialize(array $data) requires the array key 'string' (the shape produced by __serialize()). A missing key throws a native ValueError with a message styled after PHP's internal argument errors. The payload was not produced by this class's serialization, or was corrupted in storage/transit.","triggerScenarios":"unserialize() of a stored Hexadecimal payload whose array body lacks 'string' — hand-built serialized strings, cache entries from a differently-versioned producer, or truncated payloads.","commonSituations":"Caches (Redis/Memcached/APCu) or sessions holding values serialized by older code; payloads shared between systems with mismatched library expectations; corrupted serialized blobs after storage-level truncation.","solutions":["Rebuild instead of unserializing: $hex = new Hexadecimal($rawString)","Flush the stale cache/session entries so fresh values are written","Align library versions across all environments that read and write the shared store","Store the plain hex string rather than the serialized object"],"exampleFix":"// before\n$hex = unserialize($cachedValue); // array body missing 'string'\n// ValueError: Ramsey\\Uuid\\Type\\Hexadecimal::__unserialize(): Argument #1 ($data) is invalid\n\n// after: persist the hex scalar and reconstruct\n$hex = new Hexadecimal($cachedValue); // e.g. 'a1b2c3d4e5f6'","handlingStrategy":"try-catch","validationCode":"// Validate payload shape before unserializing\n$decoded = unserialize($cached, ['allowed_classes' => false]);\nif (!(is_array($decoded) && isset($decoded['string']))) {\n    // treat as a miss; rebuild from raw hex\n    $hex = new Ramsey\\Uuid\\Type\\Hexadecimal($rawHex);\n}","typeGuard":null,"tryCatchPattern":"use Ramsey\\Uuid\\Type\\Hexadecimal;\n\ntry {\n    $hex = unserialize($cached);\n} catch (\\ValueError $e) {\n    $hex = new Hexadecimal($rawHex); // rebuild from the source value\n}","preventionTips":["Store the plain hex string rather than serialized objects","Namespacing/version cache keys prevents reading foreign shapes","Align writer/reader library versions on shared stores","Treat unserialize failures as cache misses with a rebuild path"],"tags":["php","ramsey-uuid","hexadecimal","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"}