标签:
就一般约定而言,类、函数和变量的名字应该是能够让代码阅读者能够容易地知道这些代码的作用,应该避免使用凌磨两可的命名。
1. 类命名
2. 类属性命名
3. 方法的命名
1
2
3
4
5
6
7
|
class StartStudy{ //设置类 $mLessonOne = "" ; //设置类属性 $mLessonTwo = "" ; //设置类属性 function getLessonOne(){ //定义方法,得到属性mLessonOne的值 ... } } |
4. 方法中参数命名
1
2
3
4
5
|
class EchoAnyWord{ function echoWord( $firstWord , $secondWord ){ ... } } |
5. 引用变量
1
2
3
4
5
6
7
8
9
|
class Example{ $mExam = "" ; funciton setExam(& $rExam ){ ... } function getExam(){ ... } } |
6. 变量命名
7. 全局变量
8. 常量、全局常量
1
2
|
define( ‘DEFAULT_NUM_AVE‘ ,90); define( ‘DEFAULT_NUM_SUM‘ ,500); |
9. 静态变量
1
|
state $sStatus = 1; |
10. 函数命名
1
2
3
|
function this_good_idear(){ ... } |
以上的各种命名规则,可以组合一起来使用,如:
1
2
3
|
class OtherExample{ $msValue = "" ; //该参数既是类属性,又是静态变量 } |
标签:
原文地址:http://www.cnblogs.com/hcphp/p/4850088.html