This article introduces the content of the PHP naming and casing sensitive rules, has a certain reference value, now share to everyone, the need for friends can refer to
Always feel that the various casing rules in PHP is unclear, even the veteran who worked for many years may not be able to understand the size of the PHP-sensitive issues enough. In PHP, the handling of case sensitive issues is messy, we must pay attention to. Even if the case is not sensitive in some places, it is best to always stick to "case sensitive" during programming. Here are some things to note about capitalization issues:
Case sensitive
1. Variable names are case-sensitive
All variables are case-sensitive, including common variables and $_get,$_post,$_request,$_cookie,$_session, $GLOBALS, $_server,$_files,$_env, etc.
<?PHP$ABC = ' abc '; echo $abc; Output ' abc ' echo $aBc; No output echo $ABC; No output?>
2. Constant names are case-sensitive
Constants defined with define are case-sensitive.
<?phpdefine (' blogger ', ' Veitor '); echo blogger; Output ' Veitor ' echo BLOgger; Newspaper notice hint, and output ' blogger ' echo blogger; Report notice hint and output ' blogger '?>
3. Array index (key name) is case sensitive
<?php$arr = Array (' One ' = ' first '); Echo $arr [' one ']; Output ' first ' echo $arr [' one ']; No output and error echo $ARR [' one ']; As mentioned above, variable names are case-sensitive, so there is no output and an error?>
Case insensitive
1. Function names, method names, class names are case-insensitive
Although these are case-insensitive, stick to the "case sensitive" principle, it is recommended that you use names that are the same size as when you define them.
Copy Code
<?phpclass test{ static public Function Ceshi () { echo ' 123 '; } Public funcion Dxx () { echo ' 321 '; }} $obj = new Test; $obj->dxx (); Successfully instantiates the test class and calls the Dxx method output ' 321 ' $obj->dxx (); Successfully instantiates the test class and calls the Dxx method output ' 321 ' $obj = new test; $obj->dxx (); Successfully instantiates the test class and calls the Dxx method output ' 321 ' $obj->dxx (); Successfully instantiates the Test class and calls the Dxx method output ' 321 ' Test::ceshi (); Output ' 123 ' Test::ceshi (); Output ' 123 ' Test::ceshi (); Output ' 123 ' Test::ceshi (); Output ' 123 '?>
2, Magic constants are not case-sensitive
Some magic constants include: __line__, __file__, __dir__, __function__, __class__, __method__, __namespace__, etc. are not case-sensitive.
<?phpecho __line__; Output 2echo __line__; Output 3?>
3, NULL, TRUE, false case insensitive
The person who knows should be more than an example.
4. Coercion type conversions are case-insensitive
such as these
(int), (integer) – Converted to integral type
(bool), (Boolean) – converts to Boolean type
(float), (double), (real) – converts to floating-point type
(string) – converted to a string
(array) – Convert an array
(object) – Convert to Object
Generally we are lowercase, this problem is not big.
On the whole, it's easy to confuse variables, constants, class names, method names, and function names, and it helps to remember them.
Related recommendations:
Introduction to the PHP namespace
PHP namespaces and automatic loading examples