Home > Backend Development > PHP Tutorial > 26 letter case php case sensitivity issues sorted out

26 letter case php case sensitivity issues sorted out

WBOY
Release: 2016-07-29 08:47:31
Original
1609 people have browsed it

PHP's handling of case-sensitive issues is messy, and problems may occasionally occur when writing code, so I'll summarize it here.
But I am not encouraging everyone to use these rules. It is recommended that everyone always adhere to "case sensitivity" and follow unified coding standards.
1. Case sensitive
1. Variable names are case sensitive
All variables are case sensitive, including ordinary variables and $_GET, $_POST, $_REQUEST, $_COOKIE, $_SESSION, $GLOBALS, $_SERVER, $_FILES , $_ENV, etc.;

Copy the code The code is as follows:


$abc = 'abcd';
echo $abc; //Output 'abcd'
echo $aBc; //None Output
echo $ABC; //No output


2. Constant names are case-sensitive by default and are usually written in uppercase
(but I can’t find a configuration item that can change this default, please solve it)

Copy code The code is as follows:


1 define("ABC","Hello World");
echo ABC; //Output Hello World
echo abc; //Output abc


3. php.ini configuration The instructions are case-sensitive
For example, file_uploads = 1 cannot be written as File_uploads = 1
2. Case-insensitive
4. Function names, method names, and class names are not case-sensitive, but it is recommended to use the same name as when defined

Copy the code The code is as follows:


function show(){
echo "Hello World";
}
show(); //Output Hello World Recommended writing method
SHOW(); //Output Hello World


Copy code The code is as follows:


class cls{
static function func(){
echo "hello world";
}
}
Cls::FunC( ); //Output hello world


5. Magic constants are not case-sensitive, uppercase letters are recommended
including: __LINE__, __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, __NAMESPACE__.

Copy code The code is as follows:


echo __line__; //Output 2
echo __LINE__; //Output 3


6. NULL, TRUE and FALSE are not case sensitive

Copy code The code is as follows:


$a = null;
$b = NULL;
$c = true;
$d = TRUE;
$e = false;
$f = FALSE;
var_dump($a == $b); //Output boolean true
var_dump($c == $d); //Output boolean true
var_dump($e == $f); //Output boolean true


7. Type coercion, case-insensitive, includes:
* (int), (integer) – converted to integer type
* (bool), (boolean) – converted to Boolean type
* (float), (double), (real) – Convert to float
* (string) – Convert to string
* (array) – Convert to array
* (object) – Convert to object

Copy code Code As follows:


$a=1;
var_dump($a); //Output int 1
$b=(STRING)$a;
var_dump($b); //Output string '1 ' (length=1)
$c=(string)$a;
var_dump($c); //Output string '1' (length=1)

The above has introduced the arrangement of the case-sensitive issues in PHP for the 26 letters, including the content of the 26 letters. I hope it will be helpful to friends who are interested in PHP tutorials.

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