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

Asked

Viewed 161 times

3

Because, in the PHP, some predefined constants are case-insensitive (do not differentiate capital letters from minuscules) and others 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 there is an error, in the first case there is no error!

1 answer

6


Because it is possible to store constants case-insensitive see in 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 it is set to TRUE, the constant will be defined case-insensitive. The default behavior is case-sensitive; that is, constant and CONSTANT represent different values.

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

Translation: case-insensitive constants are stored in lower case.

Soon it is possible that:

__FILE__; 

__file__;

__fiLE__;

Have the same value

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

define ('CONSTANTE' , 12, true);
define ('CONSTANTe' , 12);
  • Just genius!!!! I didn’t know there was a third parameter in define!. Just like it happened with isset: I didn’t know there could be more than one parameter

  • But now, here for us, PHP has given a knife. Because what will be the constants defined by the keyword const?

  • Gets very confused just already with the defines

  • releases a translation for us :)

  • 3

    It would be good to put the command syntax as well, so we don’t depend on the link to understand the answers (the lifetime of the OS is much longer than any other XD site)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.