{"record":{"id":"5107566dea4d6f0d","repo":"laravel/framework","slug":"step-value-cannot-be-zero","errorCode":null,"errorMessage":"Step value cannot be zero.","messagePattern":"Step value cannot be zero\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/LazyCollection.php","lineNumber":100,"sourceCode":"    public static function make($items = [], ...$args)\n    {\n        return new static($items, ...$args);\n    }\n\n    /**\n     * Create a collection with the given range.\n     *\n     * @param  int  $from\n     * @param  int  $to\n     * @param  int  $step\n     * @return ($step is 0 ? never : static<int, int>)\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function range($from, $to, $step = 1, ...$args)\n    {\n        if ($step == 0) {\n            throw new InvalidArgumentException('Step value cannot be zero.');\n        }\n\n        return new static(function () use ($from, $to, $step) {\n            if ($from <= $to) {\n                for (; $from <= $to; $from += abs($step)) {\n                    yield $from;\n                }\n            } else {\n                for (; $from >= $to; $from -= abs($step)) {\n                    yield $from;\n                }\n            }\n        });\n    }\n\n    /**\n     * Get all items in the enumerable.\n     *","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/LazyCollection.php#L82-L118","documentation":"Thrown by LazyCollection::range($from, $to, $step) when $step equals 0, which would produce an infinite loop. The method generates a sequence and increments/decrements by abs($step), so zero is explicitly rejected with an InvalidArgumentException. The conditional return type marks the result as `never` when step is 0.","triggerScenarios":"LazyCollection::range(1, 10, 0); computing $step from a division or config value that resolves to 0; default-arg overrides that pass 0.","commonSituations":"Step derived from a delta (to - from) that is 0; a 'stride' config defaulting to 0; reusing a step variable that was initialised to 0 and never set.","solutions":["Pass a non-zero step (typically >= 1): LazyCollection::range($from, $to, max(1, $step)).","Guard the step before calling: if ($step == 0) { return []; }.","Validate the step value at the source (config/request) and reject zero."],"exampleFix":"// before\n$range = LazyCollection::range($min, $max, $stride);\n// after\n$range = $stride > 0\n    ? LazyCollection::range($min, $max, $stride)\n    : LazyCollection::range($min, $max, 1);","handlingStrategy":"validation","validationCode":"if ($step == 0) {\n    throw new \\InvalidArgumentException('step must be non-zero');\n}\n$range = \\Illuminate\\Support\\LazyCollection::range($from, $to, $step);","typeGuard":"$step = (is_numeric($step) && $step != 0) ? (int) $step : 1;","tryCatchPattern":"try {\n    $range = \\Illuminate\\Support\\LazyCollection::range($from, $to, $step);\n} catch (\\InvalidArgumentException $e) {\n    $range = \\Illuminate\\Support\\LazyCollection::range($from, $to, 1);\n}","preventionTips":["Always pass an explicit non-zero step default.","Validate configurable stride values against zero before use.","Add a unit test for step=0 to lock in the guard behaviour."],"tags":["lazy-collection","validation","argument-error","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}