简体   繁体   中英

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"

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM