‘%s’ operator with non-integer operand¶
Description¶
The break
and continue
operators only accept a positive non-null literal integer.
Beyond the obvious improper code that is break 1.2
, even storing the number of break levels in a constant or a variable is not a valid syntax. It can only accept an integer.
Example¶
<?php
break 1.2;
const A = 1;
break A;
?>
Literal Examples¶
‘break’ operator with non-integer operand
‘continue’ operator with non-integer operand
Solutions¶
Round the number to the closest integer.
Remove the call to break altogether.
Move the loop in a separate method, and use return to break out of the loop.
Use a goto to jump out of the loop.