Home > Backend Development > PHP Tutorial > Sorting out case-sensitive issues in PHP_PHP tutorial

Sorting out case-sensitive issues in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:21:39
Original
891 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 sensitivity
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 code The code is as follows:

< ;?php
$abc = 'abcd';
echo $abc; //output 'abcd'
echo $aBc; //no output
echo $ABC; //no output

2. Constant names are case-sensitive by default and are usually written in uppercase
(but I couldn’t find a configuration item that can change this default, please solve)
Copy the code The code is as follows:

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

3. php.ini configuration item instructions are case-sensitive
For example, file_uploads = 1 cannot be written as File_uploads = 1
two , 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 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. It is recommended to use uppercase letters
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, including:
* (int), (integer) – converted to Integer type
* (bool), (boolean) – converted to Boolean type
* (float), (double), (real) – converted to floating point type
* (string) – converted to character String
* (array) – converted to array
* (object) – converted to object
Copy code The code is 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)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324820.htmlTechArticlePHP’s handling of case-sensitive issues is messy, and problems may occasionally occur when writing code, so I’ll summarize it here. But I'm not encouraging everyone to use these rules. It is recommended that everyone always adhere to "...
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