Home  >  Article  >  Backend Development  >  PHP case problem: function names and class names are not distinguished, variable names are distinguished_PHP tutorial

PHP case problem: function names and class names are not distinguished, variable names are distinguished_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:06:201327browse

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. Variable names are case-sensitive

Copy code The code is as follows:

$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 code The code is as follows:

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

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, 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

PHP variable names are case-sensitive, while function names are not case-sensitive. This is a small detail that is often overlooked by novices. The test is as follows.

PHP variable name case sensitivity test:

Copy code The code is as follows:

$aaa = "jb51.net";
$AAA = "JB51.CN";
echo $aaa.'-'.$AAA; //jb51.net-JB51.CN
?>

PHP function name case-insensitive test:

Copy code The code is as follows:

function bbb(){
echo 'abc ';
}
function BBB(){
echo "Abc";
}
?>

The above code will report an error: ( ! ) Fatal error: Cannot redeclare BBB()

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327611.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 "...
Statement:
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