php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72548 Limit for number of lines in foreach loop
Submitted: 2016-07-05 14:12 UTC Modified: 2016-07-05 15:03 UTC
Votes:4
Avg. Score:1.5 ± 0.9
Reproduced:2 of 4 (50.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: nanovim at gmail dot com Assigned: gooh (profile)
Status: Wont fix Package: *General Issues
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nanovim at gmail dot com
New email:
PHP Version: OS:

 

 [2016-07-05 14:12 UTC] nanovim at gmail dot com
Description:
------------
I would suggest that the php interpreter/compiler would have an option to set a maximal number of lines for a foreach loop. 
We PHP Programmers love the foreach loops and they are quite usefully, but it seems this love seems often unconditional and often projects have foreach loops with hundred lines of code. This foreach loops might even complex if/then/else constructs, which may have itself foreach loops.
I think we should give the project maintainer an option to limit the number of lines of code of the foreach loops of a project.

Let's say an option in the php.ini like: foreach-limit: -1 which can be set to any Integer and -1 indicating no limit at all.



Test script:
---------------
foreach($arrray as $line)[
 //200 lines and a limit of 50
}

Expected result:
----------------
Parser error: limit of lines succeeded

Actual result:
--------------
it compiles

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-05 14:51 UTC] gooh@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: gooh
 [2016-07-05 14:51 UTC] gooh@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Consider using a static analyzer (PHP_CodeSniffer, PHPMD or PDepend, …) and implement one or more rules that would warn about such things instead. This is nothing that needs to be addressed at the interpreter/compiler level.
 [2016-07-05 15:03 UTC] nikic@php.net
-Status: Closed +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC