PHP coding specifications (5) _ PHP Tutorial

Source: Internet
Author: User
PHP coding specification (5 ). 3.6 line feed when an expression cannot be contained in a row, it can be broken according to the following general rules:-disconnect after a comma-disconnect before an operator-prefer 3.6 line feed

When an expression cannot be contained in a row, it can be disconnected according to the following general rules:

-Disconnected after a comma
-Disconnected before an operator
-Select a higher-level disconnection, rather than a lower-level disconnection.
-The new row should be aligned with the beginning of the expression of the previous row at the same level.
-If the above rules cause your code to be chaotic or make your code pile up on the right side, place them with eight spaces.

The following are examples of method call disconnection:


SomeMethod (longExpression1, longExpression2, longExpression3,
LongExpression4, longExpression5 );

$ Var = someMethod1 (longExpression1,
SomeMethod2 (longExpression2,
LongExpression3 ));

The following is an example of two disconnected arithmetic expressions. The former is better, because the disconnection is located outside the bracket expression, which is a higher level of disconnection.


$ LongName1 = $ longName2 * ($ longName3 + $ longName4-$ longName5)
+ 4 * $ longname6; // use this indent method

$ LongName1 = $ longName2 * ($ longName3 + $ longName4
-$ LongName5) + 4 * $ longname6; // avoid this

The following is an example of two indent method declarations. The former is a general situation. If the latter uses the regular indent method, it will move the second and third rows to the right, so it will be indented with 8 spaces.


// Traditional indent mode
Function someMethod ($ anArg, $ anotherArg, $ yetAnotherArg,
$ AndStillAnother ){
...
}

// Use eight consecutive spaces to avoid indentation during transition
Function horkingLongMethodName ($ anArg,
$ AnotherArg, $ yetAnotherArg,
$ AndStillAnother ){
...
}

The line feed of if statements usually uses eight spaces, because regular indentation (4 spaces) makes the statement body look hard. For example:


// Do not use this indent method
If (condition1 & condition2)
| (Condition3 & condition4)
|! (Condition5 & condition6) {// incorrect line feed mode, not indented
DoSomethingAboutIt (); // The condition is aligned with this sentence, which may be missed during reading the program.
}

// This indent method should be used
If (condition1 & condition2)
| (Condition3 & condition4)
|! (Condition5 & condition6 )){
DoSomethingAboutIt ();
}

// Or this indent method can also be used
If (condition1 & condition2) | (condition3 & condition4)
|! (Condition5 & condition6 )){
DoSomethingAboutIt ();
}

There are three feasible methods for processing the ternary expression:

$ Alpha = (aLongBooleanExpression )? Beta: gamma;

$ Alpha = (aLongBooleanExpression )? Beta
: Gamma;

$ Alpha = (aLongBooleanExpression)
? Beta
: Gamma;


Http://www.bkjia.com/PHPjc/532599.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532599.htmlTechArticle3.6 line feed when an expression cannot accommodate within a row, it can be broken according to the following general rules:-disconnect after a comma-disconnect before an operator-would rather choose more...

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.