doumaque6551 2015-09-04 12:20
浏览 129
已采纳

PHP开始标记和命名空间之间的空格

Should there be a space between <?php and namespace inside a php class file?

I am looking for this information in PSR guidelines. There are indication about a space after. But before?

PSR-2-coding-style-guid

  • 写回答

1条回答 默认 最新

  • douya5331 2015-09-04 12:43
    关注

    PSR-2 Its purpose is to have a single style guide for PHP code that results in uniformly formatted shared code.

    • Code MUST use 4 spaces for indenting, not tabs.
    • There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less.
    • There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of usedeclarations
    • Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body.
    • Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.
    • Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility
    • Control structure keywords MUST have one space after them; method and function calls MUST NOT.
    • Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body.
    • Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.

    Basic Coding Standard [PSR-2]

    *Files

    • All PHP files MUST use the Unix LF (linefeed) line ending.

    • All PHP files MUST end with a single blank line.

    • The closing ?> tag MUST be omitted from files containing only PHP.

    Lines

    • There MUST NOT be a hard limit on line length.

    • The soft limit on line length MUST be 120 characters; automated style checkers MUST warn but MUST NOT error at the soft limit.

    • Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD be split into multiple subsequent lines of no more than 80 characters each.

    • There MUST NOT be trailing whitespace at the end of non-blank lines.

    • Blank lines MAY be added to improve readability and to indicate related blocks of code.

    • There MUST NOT be more than one statement per line.

    Indenting

    • Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting.

    Keywords and True/False/Null

    • PHP keywords MUST be in lower case. ( e.g. echo , die, for, throw, catch )
    • The PHP constants true, false, and null MUST be in lower case

    NameSpace and Use Declaration

    • When present, there MUST be one blank line after the namespace declaration.
    • When present, all use declarations MUST go after the namespace declaration.
    • There MUST be one use keyword per declaration.
    • There MUST be one blank line after the use block.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题