Re: [DISCUSSION] Proposal: Introduce a loop statement
| From: | Tim Düsterhus | Date: | Tue, 01 Dec 2026 08:14:02 +0000 |
| Subject: | Re: [DISCUSSION] Proposal: Introduce a loop statement | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-133267@lists.php.net to get a copy of this message | ||
Hi
On 2026-11-27 21:05, Piotr Ziarek wrote:
is not intended to replace for, foreach or while, but to provide a simpler alternative for a common use caseThe “common use case” is a claim that I'm not sure holds up in practice. My gut feeling is that of those three a
for() loop is by far my least used loop in PHP with foreach() being the most widely used one. do-while() would likely below for().
Searching the company code base for for (, while (, foreach (, excluding tests:
- for: 50 results across 32 files.
- while: 70 results across 47 files.
- foreach: 1418 results across 492 files.
So the “by far” does not hold up, but the relative order does. A single digit number of the for() loops were not using the iteration variable within the loop itself, mostly those in debug code outside of test files.
I agree with Kamil that this requires much more evidence-based justification to become a discussable proposal.
Best regards
Tim Düsterhus