PHP advanced programming (1)

Source: Internet
Author: User
Tags coding standards return tag

PHP Advanced Programming Study Notes 20140612

Document Writing is an important part in software development. It helps future program maintenance personnel and users understand your development ideas. It also makes it easier to re-view the code in the future. The document also plays an important role in interaction between objects without understanding the details of the objects to be accessed. Documents are written in mature industry-standard formats. complying with these industry standards will help create easy-to-read representatives and make it possible to automatically generate manuals.

Code Specification

Many developers may have their own opinions on coding specifications, and they may not be the same. In fact, as long as the team members reach an agreement, it is good to follow the same standard.

The PHP community has a large number of functions, frameworks, and components. PHP developers usually use several external libraries in their own projects. Therefore, it is very important for PHP code to follow or try to be close to the same code style, developers can easily integrate multiple code libraries into their own projects. The framework interoperability group (the PHP standard group) released a series of Recommendation styles. Some of them are about the code style, that is, PSR-0, PSR-1, PSR-2 and PSR-4. In general, your PHP code should follow one or more of these standards, so that other developers can easily read and use your code. These standards are new rules attached to the previous standard, so using the PSR-1 requires compliance with the PSR-0 at the same time, but can not follow the PSR-2.

  • PSR-0 reading
  • PSR-1 reading
  • PSR-2 reading
  • PSR-4 reading
  • Read about PEAR Coding Standards
  • Read about Zend Coding Standards
  • Read about Symfony Coding Standards

Document Writing-annotation type

Three annotation methods are commonly used in PHP. annotation is a method that increases the readability and maintainability of the program, rather than the only method. Readability and maintainability are mainly improved in code naming and project organization.

// This is a single line comment type/* This is a multi-line comment type, the second line comment * // *** this form of comment is called a document comment */

The first comment can be said to be for people, and is generally used for short comments. Second, it is used in code that requires a lot of comments. The third annotation is called a document annotation, which can be interpreted and can be put in a fixed format in the manual. The main types of annotations include class comments, attribute comments, method comments, variable comments, key algorithms, and important code implementations. All these parts are woven together so that people can know exactly what you have done and why you have done so in the future.

Document Writing-grammar Parsing

The conversion process from programming language to executable code is called grammar parsing. When the grammar parser encounters a normal comment, it will recognize it and ignore it, and clear the data in the comment, so the general comment cannot be moved into the metadata.

Metadata

Metadata is defined as data about data. It is a widely used phenomenon and has specific definitions and applications in many fields. It is defined as data describing data and descriptive information about data and information resources. PHP contains the metadata of most programming elements. However, you may need to embed more metadata, because metadata is very useful in Automatic Document generation. This function can be simulated by parsing document annotations. If you create a document annotation that follows a specific format, the parser can automatically convert the annotation to a meaningful document.

PHPDoc

PHPDoc is a solution for maintaining PHP documents. It defines a structure for document comments and allows the parser to parse them in a consistent manner. With PHPDoc, you can create a manual from the embedded document. Like all document comments, PHPDoc must start with/** comments. The special feature of PHPDoc is the label. A tag is represented by a predefined identifier starting. For more information about PHPDoc, see http://www.phpdoc.org/docs/latest/index.html

PHPDoc standard comment

The comment block must start with "/** and end.

Each line between start comment and end starts with a star.

The tag must be at-sign (@) Starts with writing in the new line, and then writes the mark

There are several tags that support or need to use types to represent the types of values contained in related elements. An example here is the "param tag to determine the type of a method or function parameter.

Here is a full listing:

String:A piece of text of an unspecified length.
Int or integer:A whole number that may be either positive or negative.
Float:A real, or decimal, number that may be either positive or negative.
Bool or boolean:A variable that can only contain the state 'true' or 'false '.
Array:A collection of variables of unknown type. It is possible to specify the types of array members, see the chapter on arrays for more information.
Resource:A file handler or other system resource as described in the PHP manual.
Null:The value contained, or returned, is literally null. this type is not to be confused with void, which is the total absence of a variable or value (usually used with the @ return tag ).
Callable:A function or method that can be passed by a variable, see the PHP manual for more information on callables.

All PHPDoc labels are listed below:

@ Api @ Author @ Category @ Copyright @ Deprecated @ Example
@ Filesource @ Global @ Ignore @ Internal @ License @ Link
@ Method @ Package @ Param @ Property @ Property-read @ Property-write
@ Return @ See @ Since @ Source @ Subpackage @ Throws
@ Todo @ Uses @ Var @ Version    

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.