A constant could be a name or AN symbol for an easy worth. a continuing worth cannot modification throughout the execution of the script. By default a continuing is case-sensitiv. By convention, constant identifiers ar invariably capital. a continuing name starts with a letter or underscore, followed by any range of letters, numbers, or underscores. If you have got outlined a continuing, it will ne'er be modified or vague.
To outline a continuing you have got to use define() perform and to retrieve the worth of a continuing, you have got to easily specifying its name. in contrast to with variables, you are doing not have to be compelled to have a continuing with a $. you'll conjointly use the perform constant() to scan a constant's worth if you want to get the constant's name dynamically.
constant() function:
As indicated by the name, this perform can come the worth of the constant.
This is helpful once you need to retrieve worth of a continuing, however you are doing not recognize its name, i.e. it's keep in a very variable or came by a perform.
constant() example:
Only scalar information (boolean, integer, float and string) is contained in constants.
Differences between constants and variables are:
There is no got to write a dollar sign ($) before a relentless, wherever as in Variable one has got to write a dollar sign.
Constants can't be outlined by easy assignment, they'll solely be outlined exploitation the define() perform.
Constants is also outlined and accessed anyplace while not respect to variable scoping rules.
Once the Constants are set, might not be redefined or undefinable.
Valid and invalid constant names:
PHP Magic constants:
PHP provides an oversized range of predefined constants to any script that it runs.
There ar 5 witching constants that amendment reckoning on wherever they're used. as an example, the worth of Balinese depends on the road that it's used on in your script. These special constants ar case-insensitive and ar as follows:
A few "magical" PHP constants Ate given below:
Name Description
__LINE__ The current line range of the file.
__FILE__ The full path and computer filename of the file. If used within associate degree embody,the name of the enclosed file is came back. Sinc PHP four.0.2, __FILE__ continuously contains associate degree absolute path whereas in older versions it contained relative path beneath some circumstances.
__FUNCTION__ The perform name. (Added in PHP four.3.0) As of PHP five this constant returns the perform name because it was declared (case-sensitive). In PHP four its worth is often lowercased.
__CLASS__ The category name. (Added in PHP four.3.0) As of PHP five this constant returns the category name because it was declared (case-sensitive). In PHP four its worth is often lowercased.
__METHOD__ The category technique name. (Added in PHP 5.0.0) the strategy name is came back because it was declared (case-sensitive).
To outline a continuing you have got to use define() perform and to retrieve the worth of a continuing, you have got to easily specifying its name. in contrast to with variables, you are doing not have to be compelled to have a continuing with a $. you'll conjointly use the perform constant() to scan a constant's worth if you want to get the constant's name dynamically.
constant() function:
As indicated by the name, this perform can come the worth of the constant.
This is helpful once you need to retrieve worth of a continuing, however you are doing not recognize its name, i.e. it's keep in a very variable or came by a perform.
constant() example:
<?php define("MINSIZE", 50); echo MINSIZE; echo constant("MINSIZE"); // same thing as the previous line ?>
Only scalar information (boolean, integer, float and string) is contained in constants.
Differences between constants and variables are:
There is no got to write a dollar sign ($) before a relentless, wherever as in Variable one has got to write a dollar sign.
Constants can't be outlined by easy assignment, they'll solely be outlined exploitation the define() perform.
Constants is also outlined and accessed anyplace while not respect to variable scoping rules.
Once the Constants are set, might not be redefined or undefinable.
Valid and invalid constant names:
// Valid constant names define("ONE", "first thing"); define("TWO2", "second thing"); define("THREE_3", "third thing") // Invalid constant names define("2TWO", "second thing"); define("__THREE__", "third value");
PHP Magic constants:
PHP provides an oversized range of predefined constants to any script that it runs.
There ar 5 witching constants that amendment reckoning on wherever they're used. as an example, the worth of Balinese depends on the road that it's used on in your script. These special constants ar case-insensitive and ar as follows:
A few "magical" PHP constants Ate given below:
Name Description
__LINE__ The current line range of the file.
__FILE__ The full path and computer filename of the file. If used within associate degree embody,the name of the enclosed file is came back. Sinc PHP four.0.2, __FILE__ continuously contains associate degree absolute path whereas in older versions it contained relative path beneath some circumstances.
__FUNCTION__ The perform name. (Added in PHP four.3.0) As of PHP five this constant returns the perform name because it was declared (case-sensitive). In PHP four its worth is often lowercased.
__CLASS__ The category name. (Added in PHP four.3.0) As of PHP five this constant returns the category name because it was declared (case-sensitive). In PHP four its worth is often lowercased.
__METHOD__ The category technique name. (Added in PHP 5.0.0) the strategy name is came back because it was declared (case-sensitive).
No comments:
Post a Comment