{"record":{"id":"4dd4841a3c7c22d4","repo":"Intervention/image","slug":"normalized-color-value-must-be-in-range-0-to-1-4dd484","errorCode":null,"errorMessage":"Normalized color value must be in range 0 to 1","messagePattern":"Normalized color value must be in range 0 to 1","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Oklch/Colorspace.php","lineNumber":61,"sourceCode":"     * @see ColorspaceInterface::colorFromNormalized()\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function colorFromNormalized(array $normalized): OklchColor\n    {\n        if (!in_array(count($normalized), [3, 4])) {\n            throw new InvalidArgumentException('Number of color channels must be 3 or 4 for ' . static::class);\n        }\n\n        // add alpha value if missing\n        $normalized = count($normalized) === 3 ? array_pad($normalized, 4, 1) : $normalized;\n\n        return new Color(...array_map(\n            function (string $channel, null|float $normalized) {\n                try {\n                    return $channel::fromNormalized($normalized);\n                } catch (TypeError $e) {\n                    throw new InvalidArgumentException(\n                        'Normalized color value must be in range 0 to 1',\n                        previous: $e,\n                    );\n                }\n            },\n            self::$channels,\n            $normalized,\n        ));\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorspaceInterface::importColor()\n     *\n     * @throws ColorException\n     */\n    public function importColor(ColorInterface $color): OklchColor","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Oklch/Colorspace.php#L43-L79","documentation":"While mapping normalized values onto OKLCH channels, a value that is not a float (typically null) reached $channel::fromNormalized(); under strict types this raises a TypeError, which colorFromNormalized() rethrows as this InvalidArgumentException (src/Colors/Oklch/Colorspace.php:56-69). The null|float array type lets null pass the count check and fail only at channel construction.","triggerScenarios":"Calling Oklch\\Colorspace::colorFromNormalized([0.5, null, 30]) or with string entries like ['0.5', '0.2', '30']; nulls usually originate from nullable config values or computations whose result was null.","commonSituations":"Channel arrays assembled from user settings or database rows with nullable fields; array_map callbacks that can return null.","solutions":["Replace null entries with defaults before calling: array_map(fn($v) => $v ?? 0.0, $values)","Assert each entry is a float in 0..1 beforehand","Fix the upstream code that yields null for a channel"],"exampleFix":"// before\n$color = Oklch\\Colorspace::colorFromNormalized([$l, $c, $maybeNullHue]); // null -> this error\n\n// after\n$values = array_map(fn(?float $v): float => $v ?? 0.0, [$l, $c, $maybeNullHue]);\n$color = Oklch\\Colorspace::colorFromNormalized($values);","handlingStrategy":"validation","validationCode":"$normalized = array_map(fn(?float $v): float => $v ?? 0.0, $normalized);\nforeach ($normalized as $v) {\n    if (!is_float($v) || $v < 0.0 || $v > 1.0) {\n        // repair or reject before colorFromNormalized()\n    }\n}","typeGuard":"function isNormalizedFloatList(array $values): bool\n{\n    foreach ($values as $v) {\n        if (!is_float($v) || $v < 0.0 || $v > 1.0) { return false; }\n    }\n    return true;\n}","tryCatchPattern":null,"preventionTips":["Default nullable fields to 0.0 before building the channel array","Type callbacks so they cannot return null","Cast/validate external scalar input to float before use"],"tags":["color","oklch","colorspace","null-value","type-error","php"],"backgroundTag":"value-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}