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

Detailed explanation on whether php is case sensitive

零到壹度
零到壹度Original
2018-03-21 11:48:175331browse

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;
 ?>

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;
?>

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();
 ?>

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!

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