Closed
Description
Rule
Function
/method
call in for
loop declaration MUST be avoided.
Reason
PHP will call the method
/function
on each iteration of the for
loop.
Bad Example:
for ($i = 0; $i < count($array); $i++){
//code goes here
}
Good example:
$count = count($array);
for ($i = 0; $i < $count; $i++){
//code goes here
}
Implementation
- Subscribe to the
T_FOR
token. - Check if condition contains function call (
T_STRING
with followed by open parentheses).