Php case sensitivity

Source: Internet
Author: User

PHP handles case-sensitive issues in disorder and may occasionally encounter issues when writing code. So here is a summary.
However, I do not encourage you to use these rules. We recommend that you always adhere to the "Case sensitivity" and follow the unified code specifications.
I. Case sensitivity
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;
Copy codeThe Code is as follows:
<? Php
$ Abc = 'abc ';
Echo $ abc; // output 'abc'
Echo $ aBc; // No output
Echo $ ABC; // No output

2. Constant names are case-sensitive by default and are generally written in uppercase.
(But the default configuration item cannot be changed)
Copy codeThe Code is as follows:
1 <? Php
Define ("ABC", "Hello World ");
Echo ABC; // output Hello World
Echo abc; // output abc

3. The php. ini configuration item command is case sensitive.
For example, file_uploads = 1 cannot be written as File_uploads = 1
Ii. Case Insensitive
4. The function name, method name, and class name are case-insensitive, but the same name as the class name is recommended.
Copy codeThe Code is as follows:
<? Php
Function show (){
Echo "Hello World ";
}
Show (); // output the recommended Hello World Statement
SHOW (); // output Hello World

Copy codeThe Code is as follows:
<? Php
Class cls {
Static function func (){
Echo "hello world ";
}
}
Cls: FunC (); // output hello world

5. The magic constants are case-insensitive. uppercase is recommended.
Including: __line _, _ FILE _, _ DIR _, _ FUNCTION _, _ CLASS _, _ METHOD _, and _ NAMESPACE __.
Copy codeThe Code is as follows:
<? Php
Echo _ line __; // output 2
Echo _ LINE __; // output 3

6. NULL, TRUE, and FALSE are case insensitive.
Copy codeThe Code is as follows:
<? Php
$ A = null;
$ B = NULL;
$ C = true;
$ D = TRUE;
$ E = false;
$ F = FALSE;
Var_dump ($ a = $ B); // outputs boolean true
Var_dump ($ c ==$ d); // outputs boolean true
Var_dump ($ e = $ f); // outputs boolean true

7. Type forced conversion, case insensitive, including:
* (Int), (integer)-convert to integer
* (Bool), (boolean)-convert to boolean
* (Float), (double), (real)-convert to floating point type
* (String)-convert to string
* (Array)-convert to an array
* (Object)-convert to object
Copy codeThe Code is as follows:
<? Php
$ A = 1;
Var_dump ($ a); // output int 1
$ B = (STRING) $;
Var_dump ($ B); // output string '1' (length = 1)
$ C = (string) $;
Var_dump ($ c); // output string '1' (length = 1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.