`
sillycat
  • 浏览: 2492616 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

PHP(5)Code Standard

 
阅读更多

PHP(5)Code Standard

 

 

1. Autoloading Standard

 

Mandatory

 

\<Vendor Name>\(<Namespace>)*<Class Name>

 

 

 

Underscores in Namespaces and Class Names

 

Actually, underscore means another directory for class name.

 

 

 

example

 

\namespace\package\Class_Name => /path/to/project/lib/vendor/namespace/package/Class/Name.php

 

\namespace\package_name\Class_Name => /path/to/project/lib/vendor/namespace/package_name/Class/Name.php

 

 

 

Here is how we load the PHP class.

 

 

 

 

2. Basic Coding Standard

 

PHP code MUST use only UTF-8 without BOM.

 

 

 

3. Coding Style Guide

 

Code MUST use 4 spaces for indenting, not tabs.

 

 

 

Learn from one colleague, In Sublime, click on the line, we saw “Tab Size” at the bottom.

 

 

 

We can go to [View]>[Indentation]>Convert Indentation to Space and check [Indent Using Space]

 

 

 

There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations.

 

 

 

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;

 

 

 

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 controller structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.

 

 

 

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

 

 

 

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.

 

 

 

PHP keywords and True/False/Null MUST be in lower case. true, false, null.

 

 

 

all use declarations MUST go after the namespace declaration.

 

 

 

Visibility MUST be declared on all properties.

 

 

 

The var keyword MUST NOT be used to declare a property.

 

 

 

There MUST NOT be more than one property declared per statement.

 

 

 

4. Logger Interface

 

 

 

 

 

 

 

References:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
分享到:
评论

相关推荐

    easy-coding-standard:[只读]以0知识开始使用PHP CS Fixer和PHP_CodeSniffer的最简单方法

    composer require symplify/easy-coding-standard --dev 前缀版本 转到以获取更多信息。 用法 1.创建配置和设置检查器 在您的根目录中创建一个ecs.php 添加 ...或,你很乐意使用 // ecs.php use PhpCsFixer \ Fixer...

    phpcodesniffer-standard:PHP-TUF编码标准PHP_CodeSniffer规则(嗅探)

    PHP-TUF PHP_CodeSniffer标准 PHP-TUF PHP_CodeSniffer标准是用于PHP-TUF软件包的编码标准。 安装与使用 为了使整个PHP-TUF仓库标准化,建议采取以下步骤。 通过Composer将标准添加到您的项目中: composer config...

    OO programming with php5

    This book will help you to understand the core object-oriented programming concepts with PHP. PHP is one of the most popular ...with PHP5 full support for object-oriented programming was added to ...

    yii-coding-standard:Yii Framework PHP CodeSniffer编码标准

    CodeSniffer 安装Yii编码标准: git clone git://github.com/Ardem/yii-coding-standard.git Yii sudo ln -sv /path/to/yii-coding-standard/Yii $(pear config-get php_dir)/PHP/CodeSniffer/Standards 如果需要,...

    codeclimate-phpcodesniffer:适用于PHP的Code Climate Engine代码嗅探器

    standard-这是您希望PHP_CodeSniffer在分析文件时使用的标准的逗号分隔列表。 您可以选择包括自定义phpcs ruleset.xml文件的相对路径。 ignore_warnings-您可以隐藏警告,并且仅使用此选项报告

    PSR-1_ Basic Coding Standard - PHP-FIG.pdf

    This section of the standard comprises what should be considered the standard coding elements that are required to ensure a high level of technical interoperability between shared PHP code.

    Dayle Rees - Laravel - Code Smart - 2016

    Code samples now adhere to the PSR-2 coding standard, and use modern PHP features. Spelling and grammar have improved tenfold! Entirely new introductory and installation chapters. It's now much ...

    coding-standard:PHP_CodeSniffer 3的CodeIgniter 4编码标准

    PHP(7.1或更高版本),具有mbstring扩展名。 安装 作曲家安装 cd /Path/To/MyProject composer require codeigniter4/codeigniter4-standard --dev 在编辑器/插件配置中将phpcs standard path和phpcbf standard ...

    phpcodesniffer-composer-installer:适用于PHP_CodeSniffer编码标准的Composer安装程序

    PHP_CodeSniffer Standards Composer安装程序插件 这个作曲家安装程序插件可轻松安装编码标准(规则)。 不再需要目录的符号链接,检出特定位置的存储库或更改phpcs配置。 注意:此插件与2.x和3.x版本兼容。 用法...

    codingstandard:Marlon 编码标准,使用 PHP_Codesniffer

    马龙编码标准 PHP代码嗅探器 你需要 PEAR 的 PHP_CodeSniffer 1.3+。... 使用 phpcs --standard=path/to/php/ruleset.xml path/to/yourcode/ 运行它 PHPMD - PHP 混乱检测器 你需要 PEAR 的 PHPMD: ://phpmd.org/

    Typed.PHP.Stronger.Types.For.Cleaner.Code.1484221133

    This unique book looks at typed PHP: PHP types, strings, regular expressions, and more from PHP 7 as found in standard PHP libraries, user libraries, extensions, and cross-compilers. You'll see how ...

    Symfony-coding-standard:Symfony编码标准的开发存储库

    Symfony PHP CodeSniffer编码标准一种与编码标准进行对照的,最初是从-disappeared- opensky / Symfony2-coding-standard标准存储库无耻地复制而来的。安装作曲家该标准可以与依赖性管理器一起安装。将编码标准安装...

    CodeLobster PHP Edition Pro 4.0.1

    For now, it includes all standard abilities for operating with code and many advanced features for PHP developing. The full list of all features of Free PHP IDE: • PHP, HTML, JavaScript, CSS code ...

    CodeLobster_PHP_Edition_Pro_4.1.0

    For now, it includes all standard abilities for operating with code and many advanced features for PHP developing. The full list of all features of Free PHP IDE: • PHP, HTML, JavaScript, CSS code ...

    Code Visual Editor v2.7-汉化美化版

    Code Visual Editor v2.7代码可视化编辑器 是一个集成的代码浏览器、分析器和程序文件编辑器、代码流程图和可视化的编辑器。它可以用来浏览、 编辑文档、 可视化分析流程图的源代码,支持几乎所有的编程语言: C, C++...

    CodeLobster.PHP.Edition.Pro.4.3.2

    For now, it includes all standard abilities for operating with code and many advanced features for PHP developing. The full list of all features of Free PHP IDE: • PHP, HTML, JavaScript, CSS code ...

    CodeLobster.PHP.Edition.Pro.4.6

    featured web sites on php. For now, it includes all standard abilities for operating with code and many advanced features for PHP developing. Full description for all features you can find on Features...

    PHP外语文献

    in standard code analysis and transformation tools. As part of our work on creating analysis tools for PHP, we have conducted a study over a significant corpus of open-source PHP systems, looking at ...

    PHP 代码编辑器 CodeLobster PHP Edition 5.15.0 中文多语免费版.zip

    ·All standard functionalities for work with a code ·Drupal插件可用 ·Smarty插件可用 ·WordPress插件可用 ·Joomla插件可用 ·JQuery插件可用 ·CodeIgniter插件可用 详细的功能,请参见官方图文介绍

    PHP讲义 英文原著

    a PHP interface to the functions in an existing code library. You can even run PHP on Windows, which lets you control other Windows applications, such as Word and Excel with COM, or interact with ...

Global site tag (gtag.js) - Google Analytics