{"record":{"id":"b56a4ee7805002ee","repo":"Intervention/image","slug":"normalized-color-value-must-be-in-range-0-to-1-b56a4e","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/Oklab/Colorspace.php","lineNumber":56,"sourceCode":"     * @see ColorspaceInterface::colorFromNormalized()\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function colorFromNormalized(array $normalized): OklabColor\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): OklabColor","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Oklab/Colorspace.php#L38-L74","documentation":"While mapping normalized values onto OKLAB channels, $channel::fromNormalized() was called with something that is not a float (usually null), which under strict types raises a TypeError that colorFromNormalized() converts into this InvalidArgumentException (src/Colors/Oklab/Colorspace.php:51-64). The array entries are typed null|float, so a null slips past the count check and only fails when handed to the channel.","triggerScenarios":"Calling Oklab\\Colorspace::colorFromNormalized([0.5, null, 0.3]) or with a string entry like ['0.5', 0.1, 0.2]; nulls typically come from lookups or computations that returned null (e.g. optional config values, failed calculations) and were put into the array unfiltered.","commonSituations":"Building normalized arrays from user config or database rows where a field is nullable; using array_map with a callback that can return null.","solutions":["Filter or default null entries before calling: $normalized = array_map(fn($v) => $v ?? 0.0, $normalized)","Validate every entry with is_float() and range 0..1 before the call","Fix the upstream computation that produced null for a channel"],"exampleFix":"// before\n$color = Oklab\\Colorspace::colorFromNormalized([$l, $maybeNull, $b]); // null -> TypeError -> this error\n\n// after\n$normalized = array_map(fn(?float $v): float => $v ?? 0.0, [$l, $maybeNull, $b]);\n$color = Oklab\\Colorspace::colorFromNormalized($normalized);","handlingStrategy":"validation","validationCode":"$normalized = array_map(\n    fn(?float $v): float => $v ?? 0.0,\n    $normalized,\n);\n$invalid = array_filter($normalized, fn($v) => !is_float($v) || $v < 0.0 || $v > 1.0);\nif ($invalid !== []) {\n    // fix upstream data before calling colorFromNormalized()\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":["Never put nullable lookups into normalized arrays without a default","Type array_map callbacks to return float, not ?float","Remember strings like '0.5' fail under strict types even though they look numeric"],"tags":["color","oklab","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"}