{"record":{"id":"145fc2d448c32fad","repo":"ramsey/uuid","slug":"fields-used-to-create-a-uuidv6-must-represent-a-ve","errorCode":null,"errorMessage":"Fields used to create a UuidV6 must represent a version 6 (reordered time) UUID","messagePattern":"Fields used to create a UuidV6 must represent a version 6 \\(reordered time\\) UUID","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Nonstandard/UuidV6.php","lineNumber":60,"sourceCode":"    use TimeTrait;\n\n    /**\n     * Creates a version 6 (reordered Gregorian time) UUID\n     *\n     * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID\n     * @param NumberConverterInterface $numberConverter The number converter to use for converting hex values to/from integers\n     * @param CodecInterface $codec The codec to use when encoding or decoding UUID strings\n     * @param TimeConverterInterface $timeConverter The time converter to use for converting timestamps extracted from a\n     *     UUID to unix timestamps\n     */\n    public function __construct(\n        Rfc4122FieldsInterface $fields,\n        NumberConverterInterface $numberConverter,\n        CodecInterface $codec,\n        TimeConverterInterface $timeConverter,\n    ) {\n        if ($fields->getVersion() !== BaseUuid::UUID_TYPE_REORDERED_TIME) {\n            throw new InvalidArgumentException(\n                'Fields used to create a UuidV6 must represent a version 6 (reordered time) UUID',\n            );\n        }\n\n        parent::__construct($fields, $numberConverter, $codec, $timeConverter);\n    }\n\n    /**\n     * Converts this UUID into an instance of a version 1 UUID\n     */\n    public function toUuidV1(): UuidV1\n    {\n        $hex = $this->getHex()->toString();\n        $hex = substr($hex, 7, 5)\n            . substr($hex, 13, 3)\n            . substr($hex, 3, 4)\n            . '1' . substr($hex, 0, 3)\n            . substr($hex, 16);","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Nonstandard/UuidV6.php#L42-L78","documentation":"Ramsey\\Uuid\\Nonstandard\\UuidV6 is the deprecated pre-RFC home of version 6 UUIDs (deprecated in favor of Ramsey\\Uuid\\Rfc4122\\UuidV6). Its constructor verifies the fields actually report version 6 (UUID_TYPE_REORDERED_TIME); constructing it with fields of any other version throws InvalidArgumentException to prevent a mislabeled object.","triggerScenarios":"Directly calling new Nonstandard\\UuidV6($fields, ...) with Rfc4122FieldsInterface fields whose version nibble is not 6 — typical in code upgraded from ramsey/uuid 4.x that built v6 objects manually, custom factories, or DI containers that autowire the constructor with mismatched fields.","commonSituations":"Upgrading ramsey/uuid from 4.x to 5.x where Nonstandard\\UuidV6 still exists but builders now produce Rfc4122\\UuidV6; copy-pasted custom builder code; unit tests constructing version objects by hand.","solutions":["Replace Nonstandard\\UuidV6 with Rfc4122\\UuidV6 everywhere (the class is deprecated)","If you must construct it, feed it fields with a version-6 nibble (e.g. from Uuid::uuid6()->getFields())","Prefer factory APIs (Uuid::uuid6(), Uuid::fromString()) over manual construction"],"exampleFix":"// before\nuse Ramsey\\Uuid\\Nonstandard\\UuidV6;\n$v6 = new UuidV6($v4fields, $nc, $codec, $tc); // version 4 fields\n\n// after\nuse Ramsey\\Uuid\\Rfc4122\\UuidV6;\n$v6 = \\Ramsey\\Uuid\\Uuid::fromString('1ef0f0c8-0f4b-6f00-9f3f-0242ac110002'); // verbatim v6\n// or: $v6 = \\Ramsey\\Uuid\\Uuid::v6();","handlingStrategy":"validation","validationCode":"use Ramsey\\Uuid\\Uuid;\nif ($fields->getVersion() !== Uuid::UUID_TYPE_REORDERED_TIME) {\n    throw new InvalidArgumentException('Nonstandard\\UuidV6 requires version 6 fields');\n}\n$v6 = new \\Ramsey\\Uuid\\Nonstandard\\UuidV6($fields, $nc, $codec, $tc);","typeGuard":"function isVersion6Fields(\\Ramsey\\Uuid\\Rfc4122\\FieldsInterface $fields): bool\n{\n    return $fields->getVersion() === \\Ramsey\\Uuid\\Uuid::UUID_TYPE_REORDERED_TIME;\n}","tryCatchPattern":"try {\n    $v6 = new \\Ramsey\\Uuid\\Nonstandard\\UuidV6($fields, $nc, $codec, $tc);\n} catch (\\Ramsey\\Uuid\\Exception\\InvalidArgumentException $e) {\n    // fields are not v6; fall back to factory-generated v6\n    $v6 = \\Ramsey\\Uuid\\Uuid::uuid6();\n}","preventionTips":["Migrate from Nonstandard\\UuidV6 to Rfc4122\\UuidV6 (the class is deprecated)","Build version objects via Uuid::uuid6() rather than new","Keep custom builder code version-aware after library upgrades"],"tags":["php","ramsey-uuid","uuid-v6","deprecated","upgradability","argument-validation"],"backgroundTag":"wrong-uuid-version-for-operation","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}