Think of a variable as a glass containing water. In PHP you can define constant using define function. This means that the following will not work: PHP constants follow the same PHP variable rules. Constants are defined using PHP's define( ) function, which accepts two arguments: The name of the constant, and its value. The general syntax for defining constant is given below: define (“ConstantName” ,value); Example: define (“PI”, 3.14); However it is not mandatory to write constants in upper case, but generally programmer prefer to write them in upper case to distinguish them from variables. Variables are used to store data, like string of text, numbers, etc. Name of constants must follow the same rules as variable names, which means a valid constant name must starts with a letter or underscore, followed by any number of letters, numbers or underscores with one exception: the $ prefix is not required for constant names. Yes, You can define an array as constant. A Php global variable is accessible to all the scripts in an application. Constant within a script is accessible to any area; however, they can be scalar values.
constant() is an alternative way to get hold of a constant, but a function call can't be put into a string without concatenation either. This goes for any of the string formats in PHP, including heredoc. By Steve Suehring, Janet Valade .
The constant value is immutable. Constant, Variable, Data Type Operator: Constant: Constant refers to fixed value that does not change the value during the execution of program. You can define a class constant in php. PHP provides a large number of predefined constants to any script which it runs. Using the spl_autoload_register() function built into PHP, you can define all your later classes to extend the related "globals class" without worrying about including files manually everywhere. It is considered best practice to define constants using only upper-case names. From PHP 5.6 onwards, it is possible to define a constant as a scalar expression, and it is also possible to define an array constant. I have found different information regarding static variables in PHP but nothing that actually explains what it is and how it really works. If isSpeaking is 1, then there will be no value for Recipient Role.
Manual on constants in PHP As of PHP 5.4.6 constant() pays no attention to any namespace aliases that might be defined in the file in which it's used. For example, the value of __LINE__ depends on the line that it's used on in your script. Constants vs Variables. A local variable is only accessible to the script that it was defined in. For example, it can be started with a letter or underscore only. Note: When you assign a text value to a variable, put quotes around the value. A variable is a name given to a memory location that stores data at runtime. However, as of But your class constant would be accessible from any object instance as well.