Home > Backend Development > PHP Tutorial > Detailed explanation on whether php is case sensitive

Detailed explanation on whether php is case sensitive

零到壹度
Release: 2023-03-21 20:34:01
Original
5355 people have browsed it

According to common sense, most languages ​​​​are case-sensitive. For example, variables ab and AB are different, and functions cd and CD are also different, but PHP is a bit special.

First of all, variables and constants in php are case-sensitive.

<?php
 $a = &#39;a&#39;;
$A = &#39;A&#39;;
echo $a;
echo $A;
 ?>
Copy after login

Two variables are printed here. If they are not distinguished, the later variables should overwrite the previous ones. Let’s look at the definition of constants:

<?php
 define(&#39;a&#39;, &#39;a&#39;);
define(&#39;A&#39;, &#39;A&#39;);
echo a;
echo A;
?>
Copy after login

However, class names and method names in , and even some keywords are not case-sensitive .

<?php
 class person
{
    function say()
    {
        echo &#39;hello&#39;;
    }
}
 $p = new Person();
$p->SAY();
 ?>
Copy after login

This way of writing will not report an error, magical php, this will bring a lot of convenience, for example, under certain logic, no longer The first letter of the class name needs to be processed, but again, we should develop good code writing habits and not abuse this convenience, right? !

Related recommendations:

HTML tags are not case-sensitive

Summary of whether html css js php is case-sensitive

Small details: case distinction in css

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

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