Case sensitivity in PHP

  Peter        2012-06-25 05:48:17       14,776        0    

Case sensitivity in PHP is a bit messy. We recommend that you stick to the case sensitive rule in any language. Here we share some case sensitivity cases in PHP.

1. Case sensitive

1.1 Variable name is case sensitive

All variables names are case sensitive, these include normal variables and superglobals such as $_GET,$_POST,$_REQUEST,$_COOKIE,$_SESSION,$_GLOBALS etc.

<?php
$abc = 'abcd';
echo $abc; //Output 'abcd'
echo $aBc; //No output
echo $ABC; //No output

1.2 Constant name by default is case sensitive, usually use UPPER CASE for constant name

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

1.3 Configuration in php.ini

For example, file_uploads=1 cannot be written as File_Uploads = 1

2. Case insensitive

2.1 Function name, method name or class name are case insensitive, but we recommend that you use the same name as you define them.

Function name
<?php
    function show(){
        echo "Hello World";
    }
    show(); //Output Hello World   
    SHOW(); //Output Hello World

Method name and class name
<?php
    class cls{
    static function func(){
    echo "hello world";
    }
    }
     
    Cls::FunC();  //Output hello world

2.2. Magic constants are case insensitive

Include __LINE__,__FILE__,__DIR__,__FUNCTION__,__CLASS__,__METHOD__

<?php
    echo __line__;  //Output 2
    echo __LINE__;  //Output 3

2.3 NULL, TRUE, FALSE are case insensitive

<?php
    $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

2.4 Type casting

(int),(integer) – Convert to integer
(bool),(boolean) – convert to boolean
(float),(double),(real) – convert to floating point
(string) – convert to string
(array) – convert to array
(object) – convert to object

Source : http://hi.baidu.com/chendeping/blog/item/2239b72a708baf96033bf685.html

PHP  SUMMARY  CASE SENSITIVITY 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

MySQL DBA in training