Primary links
PHP Constants
admin — Wed, 30/08/2006 - 9:19pm
If you are looking for a data holder, which will be available anywhere in your script, including functions , then constants is the best option.
You can use the PHP function define() to create a constant. After you’ve done this, its value cannot be changed. That value can only be a number or a string. You should know that by convention, the name of the constant should be in capitals. Unlike variables, constants don’t require a dollar symbol before their name:
define(“VERSION”, 10); //defines a constant called “VERSION”
echo "Software Version : " . VERSION; // Prints 'Software Version : 10'
Constants are Global by default. So once defined, a constant will be available in any function defenition., where as in the case of a variable, you will have to explicitly declare them as global variable (eg :- global $name).
PHP also provides a number of built-in constants for you. “__FILE__”, for example, returns the name of the file currently being read by the interpreter. “__LINE__” returns the line number of the file. These constants are useful for generating error messages. You can also find out which version of PHP is interpreting the script using the “PHP_VERSION” constant.
User login
Follow Us
Who's online
Who's new
- Nisha
- linnaeus
- Yameen
- TalleyReedy
- admin

