Mediawiki.org的PHP编码约定,mediawiki.orgphp
http://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP
assignment作为expression来用看起来像个错误
<span>//</span><span> No</span> <span>if</span> ( <span>$a</span> =<span> foo() ) { bar(); }</span>
<span>//</span><span> Yes</span> <span>$a</span> =<span> foo(); </span><span>if</span> ( <span>$a</span><span> ) { bar(); }</span>
为提高代码可读性,Mediawiki大量使用空格
二元运算符
<span>//</span><span> No</span> <span>$a</span>=<span>$b</span>+<span>$c</span><span>; </span><span>//</span><span> Yes</span> <span>$a</span> = <span>$b</span> + <span>$c</span>;
函数名后面直接跟括号;括号内如有参数,两边都加空格
<span>//</span><span> Yes</span> <span>$a</span> = getFoo( <span>$b</span><span> ); </span><span>$c</span> = getBar();
控制结构 if while for foreach switch,关键字 catch,后面都有空格
<span>//</span><span> Yes</span> <span>if</span><span> ( isFoo() ) { </span><span>$a</span> = 'foo'<span>; } </span><span>//</span><span> No</span> <span>if</span><span>( isFoo() ) { </span><span>$a</span> = 'foo'<span>; }</span>
强制类型转换
<span>//</span><span> Yes</span> (int)<span>$foo</span><span>; </span><span>//</span><span> No</span> (int) <span>$bar</span><span>; ( int )</span><span>$bar</span><span>; ( int ) </span><span>$bar</span>;
注释
<span>//</span><span> Yes: Proper inline comment //No: Missing space</span>
三元运算符
除非表达式很短,否则用 If。记住一切都为了代码可读性。
"if" is English; ?: is not.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use