Search code examples
phpphpcodesniffer

Strange PHPCS error message


I have the following snippet in a php class:

$returnArray = array();
while($row = mysql_fetch_assoc($rhandle)) {
    $returnArray[] = $row;
}

phpcs complains about the 'while' line:

 161 | ERROR   | Expected "while (...) {\n"; found "while(...){\n"

Solution

  • the problem is that cs (in this case) expects a space after the while. so you need to write your code like this:

    while ($row = mysql_fetch_assoc($rhandle)) {
    }
    

    EDIT: also, see that CS is reporting that you are missing the space between ) and { when closing the while, i think you fixed it when posting the question :)