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.
<? PHP Define (' BLOGGER ', ' Veitor '); Echo BLOGGER; // output ' Veitor ' Echo BLOgger; // Newspaper notice tips 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.
<?PHPclasstest{Static Public functionCeshi () {Echo' 123 '; } Publicfuncion Dxx () {Echo' 321 '; }}$obj=NewTest;$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=Newtest;$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.
<? PHP Echo __line__; // Output 2 Echo __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.
PHP naming case Sensitive rules