psr-2

PHP PSR-2 代码风格规范 (中文版)

爷,独闯天下 提交于 2019-12-29 21:39:29
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本篇规范是 PSR-1 基本代码规范的继承与扩展。 本规范希望通过制定一系列规范化PHP代码的规则,以减少在浏览不同作者的代码时,因代码风格的不同而造成不便。 当多名程序员在多个项目中合作时,就需要一个共同的编码规范, 而本文中的风格规范源自于多个不同项目代码风格的共同特性, 因此,本规范的价值在于我们都遵循这个编码风格,而不是在于它本身。 关键词 “必须”("MUST")、“一定不可/一定不能”("MUST NOT")、“需要”("REQUIRED")、 “将会”("SHALL")、“不会”("SHALL NOT")、“应该”("SHOULD")、“不该”("SHOULD NOT")、 “推荐”("RECOMMENDED")、“可以”("MAY")和”可选“("OPTIONAL")的详细描述可参见 [RFC 2119][] 。 1. 概览 代码 必须 遵循 PSR-1 中的编码规范 。 代码 必须 使用4个空格符而不是 tab键 进行缩进。 每行的字符数 应该 软性保持在80个之内, 理论上 一定不可 多于120个, 但 一定不能 有硬性限制。 每个namespace命名空间声明语句和use声明语句块后面, 必须 插入一个空白行。 类的开始花括号({) 必须 写在函数声明后自成一行,结束花括号(})也 必须

Are parentheses required in PSR-2 PHP ternary syntax?

旧巷老猫 提交于 2019-12-21 07:55:56
问题 Question: are parentheses required in PSR-2 PHP ternary syntax? Looking for which (if either) of the following ternary statement's syntax is compliant with PSR-2 - I also need to be pointed to documentation or some authority link: $error = ($error_status) ? 'Error' : 'No Error'; OR $error = $error_status ? 'Error' : 'No Error'; Note: php.net it shows the syntax with the parentheses, but I could not find this in any of the 'official PSR-2' docs. Conclusion If there is no PSR-2 standard on this

Does PSR-2 require vertical alignment?

☆樱花仙子☆ 提交于 2019-12-10 02:42:02
问题 What is allowed between these two: $value = 'value'; $user = 'John'; $timestamp = 1480927909; $day = date('Y-m-d', $timestamp); or $value = 'value'; $user = 'John'; $timestamp = 1480927909; $day = date('Y-m-d', $timestamp); 回答1: PSR-2 does not have specific rules for this kind of inter-line alignment: From the PSR-2 Conclusion: There are many elements of style and practice intentionally omitted by this guide . These include but are not limited to: Declaration of global variables and global

Objective reasons for using spaces instead of tabs for indentation? [closed]

橙三吉。 提交于 2019-12-09 15:53:44
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . Are there objective reasons for using spaces instead of tabs for indenting files as per PSR-2 standard, can someone provide: facts, references, specific expertise on which PSR-2 standard is based? Authors of PSR-2 standard had in mind something more than "look and feel",

Does PSR-2 require vertical alignment?

女生的网名这么多〃 提交于 2019-12-05 02:07:47
What is allowed between these two: $value = 'value'; $user = 'John'; $timestamp = 1480927909; $day = date('Y-m-d', $timestamp); or $value = 'value'; $user = 'John'; $timestamp = 1480927909; $day = date('Y-m-d', $timestamp); PSR-2 does not have specific rules for this kind of inter-line alignment: From the PSR-2 Conclusion : There are many elements of style and practice intentionally omitted by this guide . These include but are not limited to: Declaration of global variables and global constants Declaration of functions Operators and assignment Inter-line alignment Comments and documentation

Are parentheses required in PSR-2 PHP ternary syntax?

半城伤御伤魂 提交于 2019-12-04 02:37:25
Question: are parentheses required in PSR-2 PHP ternary syntax? Looking for which (if either) of the following ternary statement's syntax is compliant with PSR-2 - I also need to be pointed to documentation or some authority link: $error = ($error_status) ? 'Error' : 'No Error'; OR $error = $error_status ? 'Error' : 'No Error'; Note: php.net it shows the syntax with the parentheses, but I could not find this in any of the 'official PSR-2' docs. Conclusion If there is no PSR-2 standard on this, which way is the most common convention? The PSR-2 standard specifically omits any opinion on

What is the difference between StudlyCaps and CamelCase?

喜夏-厌秋 提交于 2019-12-03 09:19:24
问题 PSR suggests, method names MUST be declared in camelCase and class names MUST be declared in StudlyCaps. 回答1: StudlyCaps, also known as PascalCase, implies that the first capital of each subword is capitalized. camelCase implies, like a camel, that the humps are in the middle, therefore the first letter is not capitalized. Compare Microsoft's standards for .NET. Other well known capitalization styles are snake_case, where all words are concatenated in lowercase with underscores, and kebab