{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/LazyCollection.php#L82-L118","documentation":"Thrown by LazyCollection::range($from, $to, $step) when $step equals 0. A zero step would produce an infinite loop (the value never advances toward $to), so the guard prevents that. Note the check uses == so 0, 0.0, and '0' all trigger it.","triggerScenarios":"Calling LazyCollection::range(1, 10, 0). Most often $step comes from a calculation or input that can yield 0, e.g. range(0, 100, $end - $start) when $end === $start.","commonSituations":"Dynamic step computed from user input or measurement deltas that can be 0. Defaulting $step from config that resolves to 0. Off-by-one in endpoint math producing equal bounds.","solutions":["Ensure $step is a non-zero number; guard with if ($step == 0) return collect().","Clamp the step away from zero, or compute it only when bounds differ.","Validate the source of $step before calling range()."],"exampleFix":"// before\n$range = LazyCollection::range($start, $end, $end - $start);\n\n// after\n$step = $end - $start;\n$range = $step == 0\n    ? LazyCollection::range($start, $end, 1)\n    : LazyCollection::range($start, $end, $step);","handlingStrategy":"validation","validationCode":"if ($step == 0) {\n    $range = \\Illuminate\\Support\\LazyCollection::range($from, $to, 1);\n} else {\n    $range = \\Illuminate\\Support\\LazyCollection::range($from, $to, $step);\n}","typeGuard":"function isNonZeroStep($step): bool { return is_numeric($step) && $step != 0; }","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":["Never compute step as a difference of possibly-equal bounds without guarding for 0.","Validate dynamic step inputs at the boundary."],"tags":["laravel","collections","lazy","validation","invalid-argument"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}