PHP Code Specification Method Tutorial

Source: Internet
Author: User

SomeMethod (LongExpression1, LongExpression2, LongExpression3,
LongExpression4, LONGEXPRESSION5);

$var = SomeMethod1 (LongExpression1,
SOMEMETHOD2 (LongExpression2,
LongExpression3));

Here are two examples of broken arithmetic expressions. The former is better because the disconnect is outside the bracket expression, which is a higher level disconnect.


$longName 1 = $longName 2 * ($longName 3 + $longName 4-$longName 5)
+ 4 * $longname 6; Use this indentation method

$longName 1 = $longName 2 * ($longName 3 + $longName 4
-$longName 5) + 4 * $longname 6; Avoid this

The following is an example of two indentation method declarations. The former is a conventional case. The latter, if used in normal indentation, will move the second and third rows to the right, so instead indent 8 spaces


The traditional indentation method
function SomeMethod ($ANARG, $anotherArg, $YETANOTHERARG,
$andStillAnother) {
...
}

Use 8 consecutive spaces to avoid indentation of transitions
function Horkinglongmethodname ($ANARG,
$anotherArg, $yetAnotherArg,
$andStillAnother) {
...
}

The wrapping of an if statement usually uses a 8-space rule, because a regular indent (4 spaces) makes the statement body look more laborious. Like what:


Do not use this indentation method
if ((Condition1 && condition2)
|| (Condition3 && Condition4)
||! (Condition5 && Condition6)) {//Wrong line wrapping, no indentation
Dosomethingaboutit (); The condition is aligned with this sentence, causing the reading program to miss this sentence.
}

You should use this indentation method
if ((Condition1 && condition2)
|| (Condition3 && Condition4)
||! (Condition5 && Condition6)) {
Dosomethingaboutit ();
}

Or this indentation way can also
if ((condition1 && condition2) | | (Condition3 && Condition4)
||! (Condition5 && Condition6)) {
Dosomethingaboutit ();
}

Here are three possible ways to deal with ternary expressions:

$alpha = (alongbooleanexpression)? Beta:gamma;

$alpha = (alongbooleanexpression)? Beta
: Gamma;

$alpha = (alongbooleanexpression)
? Beta
: Gamma;
Download PHP Code specification CHM

Http://down.111cn.net/down/help/php/2009/0301/phpchm.html

Better in various programming online Help manuals please go to

http://111cn.net/help/View

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.