·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> Mediawiki.org的PHP编码约定

Mediawiki.org的PHP编码约定

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
Mediawiki.org的php编码约定

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

assignment作为exPRession来用看起来像个错误(looks surprising)

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

为提高代码可读性,Mediawiki大量使用空格(spaces are cheap; you are a good typist)

二元运算符

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

函数名后面直接跟括号;括号内如有参数,两边都加空格

// Yes$a = getFoo( $b );$c = getBar();

控制结构 if while for foreach switch,关键字 catch,后面都有空格

// Yesif ( isFoo() ) {    $a = 'foo';} // Noif( isFoo() ) {    $a = 'foo';}

强制类型转换

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

注释

// Yes: Proper inline comment//No: Missing space

三元运算符

除非表达式很短,否则用 if。记住一切都为了代码可读性。

// "if" is English; ?: is not.