Home > Backend Development > PHP Tutorial > PHP Naming Convention [Transfer]_PHP Tutorial

PHP Naming Convention [Transfer]_PHP Tutorial

WBOY
Release: 2016-07-20 11:13:27
Original
1074 people have browsed it

 

【转】谭博的个人网站

<pre class="code"><pre [类]
Copy after login
<pre 1.类名与类文件名采用驼峰式且首字母大写<pre 2.类私有属性和私有方法名称以下划线开头
Copy after login
<pre 3.方法名使用驼峰式<pre
Copy after login
<pre <pre
Copy after login
<pre [变量]<pre 变量名使用小写字母加下划线
Copy after login
<pre
<pre <pre
Copy after login
<pre [函数]
<pre 函数名使用小写字母加下划线<pre
Copy after login
<pre [缩进]<pre 函数方法中代码块缩进4个空格
Copy after login
<pre 语句如foreach switch后需加一个空格
Copy after login
<pre 定义函数,方法名时加一个空格,如 function test() {<pre 函数调用时不使用缩进,如 :test();
Copy after login
<pre 函数或方法有多个参数时需在逗号后面加一个空格,如test($a, $b, $c);<pre 赋值运算等号前后需要一个空格,如:$a = ‘b’;
Copy after login
<pre 三目运算需使用空格分割,如:$a = 1 ? 2 : 3;<pre 逻辑运算符前后需要一个空格,如:($a == $b)
Copy after login
<pre 如碰到需要换行的情况,以4个空格开头<pre
Copy after login
<pre [换行]<pre 每行代码最大长度建议值为85,不要超过100
Copy after login
<pre 尽量使用简洁的变量名,如果代码过长可使用赋值的方式将其分解<pre 如果优化后还是过长,可使用换行
Copy after login
<pre 非数字元素数组建议一行一个元素<pre
Copy after login
<pre [注释]<pre 行注释用
Copy after login
<pre 代码块注释使用
Copy after login
<pre <pre [代码优化]
Copy after login
<pre 尽量减少if else语句的嵌套,一是为了减少代码的缩进,二是减轻逻辑复杂度
Copy after login

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/440372.htmlTechArticle【转】谭博的个人网站 switch后需加一个空格 ($a == $b)...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template