{"record":{"id":"0ce670bfd7b24753","repo":"ramsey/uuid","slug":"s-argument-1-data-is-invalid-0ce670","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/Uuid.php","lineNumber":349,"sourceCode":"\n        /** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */\n        $this->numberConverter = $uuid->numberConverter;\n\n        /** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */\n        $this->fields = $uuid->fields;\n\n        /** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */\n        $this->timeConverter = $uuid->timeConverter;\n    }\n\n    /**\n     * @param array{bytes?: string} $data\n     */\n    public function __unserialize(array $data): void\n    {\n        // @codeCoverageIgnoreStart\n        if (!isset($data['bytes'])) {\n            throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));\n        }\n        // @codeCoverageIgnoreEnd\n\n        $this->unserialize($data['bytes']);\n    }\n\n    public function compareTo(UuidInterface $other): int\n    {\n        $compare = strcmp($this->toString(), $other->toString());\n\n        if ($compare < 0) {\n            return -1;\n        }\n\n        if ($compare > 0) {\n            return 1;\n        }\n","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Uuid.php#L331-L367","documentation":"When PHP unserializes a Ramsey\\Uuid\\Uuid object, __unserialize(array $data) requires the array key 'bytes' (the 16-byte string emitted by __serialize()/serialize()). A payload missing that key throws a native ValueError with a message styled like PHP's internal argument errors. Serialized UUID objects in caches, sessions or queues become malformed when truncated, written by other code, or hand-built.","triggerScenarios":"unserialize() of a stored Uuid payload whose array body lacks 'bytes' — e.g. cache entries from a different producer, truncated serialized blobs, or serialized data passed through unserialize() with allowed_classes reshaping.","commonSituations":"UUIDs cached as serialized objects in Redis/sessions; queue messages carrying serialized UUIDs across service versions; corrupted storage after crashes; test fixtures with literal serialized strings.","solutions":["Store the canonical UUID string instead and rebuild with Uuid::fromString($string) on read","Treat the malformed entry as a cache miss and regenerate the value","Flush/expire stale serialized entries after deploying serialization changes","Align library versions between the writer and reader of the shared store"],"exampleFix":"// before\n$uuid = unserialize($cachedUuid);\n// ValueError: Ramsey\\Uuid\\Uuid::__unserialize(): Argument #1 ($data) is invalid\n\n// after: cache the canonical string and rebuild\n$uuid = Uuid::fromString($cachedUuidString); // e.g. 'a3f3df0e-6f8b-4c1a-9d2e-4b0c8f7a1d23'","handlingStrategy":"try-catch","validationCode":"// Validate shape before trusting a stored payload\n$decoded = unserialize($cached, ['allowed_classes' => false]);\nif (!(is_array($decoded) && isset($decoded['bytes']))) {\n    // treat as cache miss; rebuild from the canonical string\n    $uuid = Ramsey\\Uuid\\Uuid::fromString($uuidString);\n}","typeGuard":null,"tryCatchPattern":"use Ramsey\\Uuid\\Uuid;\n\ntry {\n    $restored = unserialize($cached);\n} catch (\\ValueError $e) {\n    $restored = Uuid::fromString($canonicalString); // rebuild from the stored text form\n}","preventionTips":["Persist UUIDs as their canonical 36-character string (or 32 hex) and rebuild via Uuid::fromString()","Avoid caching serialized Uuid objects across deploys","Catch ValueError when unserializing anything from storage and fall back to reconstruction","Version cache keys to force invalidation after serialization changes"],"tags":["php","ramsey-uuid","uuid","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"}