{"record":{"id":"c9ae542cf3f05730","repo":"ramsey/uuid","slug":"s-argument-1-data-is-invalid-c9ae54","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/Integer.php","lineNumber":112,"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 numeric-string\n     */\n    private function prepareValue(float | int | string $value): string\n    {\n        $value = (string) $value;\n        $sign = '+';\n\n        // If the value contains a sign, remove it for the digit pattern check.\n        if (str_starts_with($value, '-') || str_starts_with($value, '+')) {\n            $sign = substr($value, 0, 1);\n            $value = substr($value, 1);","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Type/Integer.php#L94-L130","documentation":"When PHP unserializes a Ramsey\\Uuid\\Type\\Integer object, __unserialize(array $data) requires the array key 'string' (the shape emitted by __serialize()). A payload missing that key triggers a native ValueError with a PHP-internal-style message. The data being unserialized was not produced by this class or was corrupted.","triggerScenarios":"unserialize() of an Integer payload whose array body lacks 'string' — hand-crafted serialized strings, cache/session values written by different code, or payloads altered in storage.","commonSituations":"Shared caches or sessions spanning application versions; serialized blobs migrated between systems; test fixtures containing literal serialized strings that drift from the real format.","solutions":["Rebuild the object from its scalar: $integer = new Integer($rawNumericString)","Purge the malformed cache/session entries","Keep the code that writes and reads serialized values on the same library version","Store numeric strings and instantiate Integer at read time instead of serializing objects"],"exampleFix":"// before\n$integer = unserialize($cachedValue); // payload missing 'string'\n// ValueError: Ramsey\\Uuid\\Type\\Integer::__unserialize(): Argument #1 ($data) is invalid\n\n// after: cache the numeric string, reconstruct on read\n$integer = new Integer($cachedValue); // e.g. '12345678901234567890'","handlingStrategy":"try-catch","validationCode":"// Validate payload shape before unserializing\n$decoded = unserialize($cached, ['allowed_classes' => false]);\nif (!(is_array($decoded) && isset($decoded['string']))) {\n    // rebuild from the source numeric string\n    $integer = new Ramsey\\Uuid\\Type\\Integer($rawNumeric);\n}","typeGuard":null,"tryCatchPattern":"use Ramsey\\Uuid\\Type\\Integer;\n\ntry {\n    $integer = unserialize($cached);\n} catch (\\ValueError $e) {\n    $integer = new Integer($rawNumeric); // rebuild from the canonical value\n}","preventionTips":["Cache numeric strings instead of serialized Integer objects","Version cache keys when serialization shapes can change","Keep the producing and consuming code on the same library version","Always provide a rebuild path when unserializing stored data"],"tags":["php","ramsey-uuid","integer","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"}