Is php case sensitive?

青灯夜游
Release: 2023-02-26 10:40:01
Original
4259 people have browsed it

In the process of developing PHP, because naming case issues can easily lead to code errors, we have compiled some information on PHP case sensitivity from the Internet. Friends who need it can refer to it.

Is php case sensitive?

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'm 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

<?php
 $abc = &#39;abcd&#39;;
 echo $abc; //输出 &#39;abcd&#39;
 echo $aBc; //无输出
 echo $ABC; //无输出
Copy after login

2. Constant names are case-sensitive by default and are usually written in uppercase

Constants defined using define are case-sensitive.

<?php
define(&#39;BLOGGER&#39;,&#39;Veitor&#39;);
echo BLOGGER;    //输出&#39;Veitor&#39;
echo BLOgger;    //报NOTICE提示,并输出&#39;BLOgger&#39;
echo blogger;    //报NOTICE提示,并输出&#39;blogger&#39;
?>
Copy after login

3. Function names, method names, and class names are not case-sensitive

But it is recommended to use the same name as when defined

<?php
 function show(){
 echo "Hello World";
 }
Copy after login

show (); //Output Hello World. Recommended writing method

SHOW(); //Output Hello World

<?php
 class cls{
 static function func(){
 echo "hello world";
 }
 }
 Cls::FunC(); //输出hello world
Copy after login

4. Magic constants are not case-sensitive. Capital letters are recommended

Includes: __LINE__, __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, __NAMESPACE__.

<?php
 echo __line__; //输出 2
 echo __LINE__; //输出 3
Copy after login

5. NULL, TRUE and FALSE are not case-sensitive

<?php
 $a = null;
 $b = NULL;
 $c = true;
 $d = TRUE;
 $e = false;
 $f = FALSE;
 var_dump($a == $b); //输出 boolean true
 var_dump($c == $d); //输出 boolean true
 var_dump($e == $f); //输出 boolean true
Copy after login

5. Array index (key name) is case-sensitive

<?php
$arr = array(&#39;one&#39;=>&#39;first&#39;);
echo $arr[&#39;one&#39;];    //输出&#39;first&#39;
echo $arr[&#39;One&#39;];    //无输出并报错
echo $Arr[&#39;one&#39;];    //上面讲过,变量名区分大小写,所以无输出并报错
?>
Copy after login

Summary:

In PHP, function names, method names, class names, and keywords are not case-sensitive; but variables Names and constant names are case-sensitive.

The above is the detailed content of Is php case sensitive?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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