Home  >  Article  >  Backend Development  >  What are the contents of PHP's PSR series of specifications? What are the phppsr specifications?_PHP Tutorial

What are the contents of PHP's PSR series of specifications? What are the phppsr specifications?_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:12988browse

What are the contents of PHP’s PSR series of specifications? What are the contents of phppsr specifications?

PSR

is the abbreviation of PHP Standard Recommendation. It should actually be called PSRs, which is a series of recommended standards: currently passed specifications include PSR-0 (Autoloading Standard), PSR-1 (Basic Coding Standard), PSR-2 (Coding Style Guide) ), PSR-3 (Logger Interface), PSR-4 (Improved Autoloading). It is not an official PHP standard, but a series of standards extracted from well-known PHP projects such as Zend and Symfony2. Currently, more and more community projects have joined as members and follow this standard.

PHP-FIG — PHP Framework Interoperability Group, is an organization that formulates PSRs development specifications. Its members are composed of many well-known PHP community projects. You can see the member list at the bottom of its official website homepage. These members develop specifications and implement them in their projects.

In fact, the content of each PSR specification is very concise and clear, which is much better than those specifications that span dozens of pages.

PSR-0(Autoloading Standard)

PSR-0 is the automatic class loading specification (original text: official website, GitHub). As of 2014-10-21, this specification is marked Deprecated and replaced by PSR-4. Its content is very concise.

Content:

PSR-1(Basic Coding Standard)

PSR-1 is the basic coding standard (original text: official website, GitHub). Is the content concise, including the naming method of class files, class names, and class method names?

Content:

PSR-2(Coding Style Guide)

PSR-2 is the coding style standard (original text: official website, GitHub). The content is slightly more, but it is still relatively concise. It is based on PSR-1 and includes relevant provisions for indentation, length of each line of code, line breaks, method visibility declarations, spaces, and method body brace wrapping.

Standard content:

PSR-3(Logger Interface)

PSR-3 is the definition of application log class through interface (original text: official website, GitHub). The content is very simple, it is just an interface. Just quote the official sample code. Of course, in specific applications, as long as you follow this interface, you can definitely customize the corresponding implementation.

Basic content:

PSR-4(Improved Autoloading)

PSR-4 is an improved version of the automatic loading specification (original text: official website, GitHub). It is the successor to the PSR-0 specification. It is compatible with any other autoloading specification, including PSR-0.

Content:

  • When loading a file from a fully qualified class name:
  • The implementation of the autoloader must not throw any exceptions or cause errors of any level; nor should it return a value

  • Note: The specific specification content is compiled with reference to other Chinese translation versions.

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947048.htmlTechArticleWhat are the contents of PHP’s PSR series specifications? What are the contents of phppsr specifications? PSR is the abbreviation of PHP Standard Recommendation. It is actually It should be called PSRs, that is, a series of recommended standards: the currently adopted specifications include PSR...
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn