Why, in PHP, are some predefined constants case-insensitive?

3

Because in PHP , some predefined constants are case-insensitive (they are not case sensitive) and some are not?

Example 1:

echo __FILE__; // index.php

echo __file__; // index.php

echo __fiLE__; // index.php

Example 2:

echo PHP_EOL; \n

echo php_eol; // Use of undefined constant php_EOL - assumed 'php_eol' 

echo php_EOL; // Use of undefined constant php_EOL - assumed 'php_EOL' 

As you can see, in the last case it generates an error, it does not generate any errors in the first one!

    
asked by anonymous 15.07.2015 / 16:29

1 answer

6

Because it is possible to store constants in a case-insensitive way, see the documentation Link

  

If set to TRUE, the constant will be defined case-insensitive. The default behavior is case-sensitive; i.e. CONSTANT and Constant represent different values.

Translation: If set to TRUE, the case-insensitive constant will be defined. The default behavior is case-sensitive; or constant and CONSTANT represent different values.

  

Note:   Case-insensitive constants are stored as lower-case.

Translation: Case-insensitive constants are stored in the box.

Soon it is possible that:

__FILE__; 

__file__;

__fiLE__;

Have the same value

Constants creation command (One of them is possible to create constants with the word const ).

define ('CONSTANTE' , 12, true);
define ('CONSTANTe' , 12);
    
15.07.2015 / 16:37