PHP Coding conventions for MediaWiki.org

Source: Internet
Author: User
Tags mediawiki

Http://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP

Assignment as expression to look like a mistake

// No if $a = foo ()) {    bar ();}
// Yes $a = foo (); if $a ) {    bar ();}

To improve code readability, MediaWiki uses a large number of spaces

Binary operators

// No $a=$b+$c//  Yes$a$b$c;

The function name is followed by parentheses, and if there are parameters in parentheses, spaces are added to both sides.

// Yes $a $b  ); $c = Getbar ();

Control structure if and for foreach switch, keyword catch, followed by spaces

// Yes if (Isfoo ()) {    $a = ' foo '//  Noif(Isfoo ()) {     $a = ' foo ';}

Forcing type conversions

// Yes (int) $foo  //  No$bar;(int)$bar$bar;

Comments

// yes:proper inline comment//no:missing space

Ternary operators

Unless the expression is short, use if. Remember that everything is for code readability.

"If" is 中文版;?: Is not.

PHP Coding conventions for MediaWiki.org

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.