anru
anru

Reputation: 1414

PHP coding standard

I am checking this PHP quality control tool: PHP_CodeSniffer

In its documentation page Example Section, it shows Usage of the tool:

 $ phpcs /path/to/code/myfile.php

 FILE: /path/to/code/myfile.php
 --------------------------------------------------------------------------------
 FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
 --------------------------------------------------------------------------------
   2 | ERROR | Missing file doc comment
  20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
  47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
  51 | ERROR | Missing function doc comment
  88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
 --------------------------------------------------------------------------------

on line 2

20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"', my question is why lower case "false" and "true".

according to PHP's documentation: "A boolean expresses a truth value. It can be either TRUE or FALSE"

Upvotes: 0

Views: 707

Answers (2)

Alice Wonder
Alice Wonder

Reputation: 916

CodeSniffer defaults to the PEAR coding standard. What is an error in CodeSniffer does not necessarily mean it is incorrect but often simply means it does not conform to the agreed upon PEAR coding standard. If you are writing your code for PEAR you should fix it. Otherwise, don't worry about it.

I believe you can configure CodeSniffer to check against a different coding standard (for example, if you prefer a standard that uses tabs instead of spaces for indenting, etc.) if you do not like the PEAR standard.

Upvotes: 1

Emir Akaydın
Emir Akaydın

Reputation: 5823

Yes, PHP documentation says "TRUE or FALSE" but also says;

Syntax

To specify a boolean literal, use the keywords TRUE or FALSE. Both are case-insensitive.

So, even if PHP_CodeSniffer says

PHP keywords must be lowercase; expected "false" but found "FALSE"

it doesn't matter actually. You can change all boolean values to lowercase to skip this error message if you really care that much.

Upvotes: 2

Related Questions