PHP区分大小写:函数名和类名不区分,变量名区分

WBOY
Release: 2016-06-20 13:03:41
Original
1649 people have browsed it

PHP对大小写敏感问题的处理比较乱,写代码时可能偶尔出问题,所以这里总结一下。但我不是鼓励大家去用这些规则。推荐大家始终坚持“大小写敏感”,遵循统一的代码规范。

1. 变量名区分大小写

<p><?php</p><p>$abc = 'abcd';</p><p>echo $abc; //输出 'abcd'</p><p>echo $aBc; //无输出</p><p>echo $ABC; //无输出</p>
Copy after login

2. 常量名默认区分大小写,通常都写为大写

(但没找到能改变这个默认的配置项,求解)

<p><?php</p><p>define("ABC","Hello World");</p><p>echo ABC; //输出 Hello World</p><p>echo abc; //输出 abc</p>
Copy after login

php.ini配置项指令区分大小写

如 file_uploads = 1 不能写成 File_uploads = 1

3. 函数名、方法名、类名不区分大小写

但推荐使用与定义时相同的名字

<p><?php</p><p>function show(){</p><p>echo "Hello World";</p><p> }</p><p>show(); //输出 Hello World 推荐写法</p><p>SHOW(); //输出 Hello World</p>
Copy after login

<p><?php</p><p>class cls{</p><p>static function func(){</p><p>echo "hello world";</p><p>}</p><p>}</p><p>Cls::FunC(); //输出hello world</p>
Copy after login

4. 魔术常量不区分大小写,推荐大写

包括:__LINE__、__FILE__、__DIR__、__FUNCTION__、__CLASS__、__METHOD__、__NAMESPACE__。

<p><?php</p><p>echo __line__; //输出 2</p><p>echo __LINE__; //输出 3</p>
Copy after login

5. NULL、TRUE、FALSE不区分大小写

<p><?php</p><p>$a = null;</p><p>$b = NULL;</p><p>$c = true;</p><p>$d = TRUE;</p><p>$e = false;</p><p>$f = FALSE;</p><p>var_dump($a == $b); //输出 boolean true</p><p>var_dump($c == $d); //输出 boolean true</p><p>var_dump($e == $f); //输出 boolean true</p>
Copy after login


Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!