PHP case: function and class names are not distinguished variable names are distinguished

  • 2020-06-12 08:46:26
  • OfStack

PHP's handling of case-sensitive issues is messy, and there may be occasional problems when writing code, so here is a summary of 1.
But I'm not encouraging you to use these rules. It is recommended that you always adhere to "case sensitive" and follow the code specification of Unified 1.

1. Variable names are case sensitive


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

2. Constant names are case-sensitive by default and are usually written in uppercase
(But can not find to change this default configuration item, solve)


 <?php
 define("ABC","Hello World");
 echo ABC; // The output  Hello World
 echo abc; // The output  abc

3. php. ini configuration instructions are case sensitive
For example, file_uploads = 1 cannot be written as File_uploads = 1

4. Function, method, and class names are case insensitive
However, it is recommended to use the same name as defined


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

show (); // Output Hello World recommended

SHOW (); // Output Hello World


 <?php
 class cls{
 static function func(){
 echo "hello world";
 }
 }
 Cls::FunC(); // The output hello world

5. Magic constants are case insensitive and upper case are recommended
Including: __LINE__, __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, __NAMESPACE__.


 <?php
 echo __line__; // The output  2
 echo __LINE__; // The output  3

6. NULL, TRUE, FALSE are case insensitive


 <?php
 $a = null;
 $b = NULL;
 $c = true;
 $d = TRUE;
 $e = false;
 $f = FALSE;
 var_dump($a == $b); // The output  boolean true
 var_dump($c == $d); // The output  boolean true
 var_dump($e == $f); // The output  boolean true 

PHP variable names are case sensitive, function names are case insensitive, and small details often overlooked by newbies are tested as follows.

PHP variable name case sensitive test:


<?php 
    $aaa = "ofstack.com"; 
    $AAA = "JB51.CN"; 
    echo $aaa.'-'.$AAA;  //ofstack.com-JB51.CN 
?> 

PHP function name is case-insensitive:


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

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


Related articles: