If you look up the word constant in a dictionary it will probably tell you that the word is used to describe something that is non-changing and non-variable, and this is exactly the purpose of constants in PHP. A PHP constatnt is the opposite of a variable in that once it has been defined it cannot be changed.
 
If you look up the word constant in a dictionary it will probably tell you that the word is used to describe something that is non-changing and non-variable, and this is exactly the purpose of constants in PHP. A PHP constatnt is the opposite of a variable in that once it has been defined it cannot be changed.
   −
Constants are particularly useful for defining a value that you frequently need to refer to that does not ever change. For example, you might define a constant called INCHES_PER_YARD that contains the number of inches in a yard. Since this is a value that typically doesn't change it makes sense to define it as a constant. Conversely, a value that is likely to change, such as the Dollar to Yen exchange rate is best defined as a variable.
+
Constants are particularly useful for defining a value that you frequently need to refer to that does not ever change. For example, you might define a constant called INCHES_PER_YARD that contains the number of inches in a yard. Since this is a value that typically doesn't from one day to the next it makes sense to define it as a constant. Conversely, a value that is likely to change, such as the Dollar to Yen exchange rate is best defined as a variable.
    
PHP constants are said to have ''global scope''. This basically means that once you have defined a constant it is accessible from any function or object in your script.  
 
PHP constants are said to have ''global scope''. This basically means that once you have defined a constant it is accessible from any function or object in your script.  
 
The define function takes two arguments, the first being the name you wish to assign to the constant, and the second the value to assign to that name.  
 
The define function takes two arguments, the first being the name you wish to assign to the constant, and the second the value to assign to that name.  
   −
Constant name are case sensitive. Althouth it is not a requirement, convention carried over from other programming languages suggests that constants should be named in all upper case characters. The following example demonstrates the use of the ''define()'' function to specify a constant:
+
Constant name are case sensitive. Although it is not a requirement, convention carried over from other programming languages suggests that constants should be named in all upper case characters. The following example demonstrates the use of the ''define()'' function to specify a constant:
    
<pre>
 
<pre>
 
</pre>
 
</pre>
   −
we can subsequently access that value anywhere in our script. For example to display the value:
+
we can subsequently access that value anywhere in our script. For example, to display the value:
    
<pre>
 
<pre>
 
It can often be useful to find out if a constant is actually defined. This can be achieved using the PHP ''defined()'' function. The ''defined()'' function takes the name of the constant to be checked as an argument and returns a value of ''true'' or ''false'' (i.e 1 or 0) to indicate whether that constant exists.
 
It can often be useful to find out if a constant is actually defined. This can be achieved using the PHP ''defined()'' function. The ''defined()'' function takes the name of the constant to be checked as an argument and returns a value of ''true'' or ''false'' (i.e 1 or 0) to indicate whether that constant exists.
   Exception encountered, of type "Error"
[9dc7c80f] /index.php?diff=next&oldid=1115&title=PHP_Constants Error from line 434 of /var/www/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /var/www/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /var/www/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /var/www/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /var/www/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /var/www/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /var/www/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /var/www/techotopia/includes/diff/TableDiffFormatter.php(194): WordLevelDiff->__construct()
#7 /var/www/techotopia/includes/diff/DiffFormatter.php(140): TableDiffFormatter->changed()
#8 /var/www/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /var/www/techotopia/includes/diff/DifferenceEngine.php(881): DiffFormatter->format()
#10 /var/www/techotopia/includes/diff/DifferenceEngine.php(797): DifferenceEngine->generateTextDiffBody()
#11 /var/www/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /var/www/techotopia/includes/diff/DifferenceEngine.php(662): DifferenceEngine->getDiffBody()
#13 /var/www/techotopia/includes/diff/DifferenceEngine.php(632): DifferenceEngine->getDiff()
#14 /var/www/techotopia/includes/diff/DifferenceEngine.php(453): DifferenceEngine->showDiff()
#15 /var/www/techotopia/includes/page/Article.php(797): DifferenceEngine->showDiffPage()
#16 /var/www/techotopia/includes/page/Article.php(508): Article->showDiffPage()
#17 /var/www/techotopia/includes/actions/ViewAction.php(44): Article->view()
#18 /var/www/techotopia/includes/MediaWiki.php(490): ViewAction->show()
#19 /var/www/techotopia/includes/MediaWiki.php(287): MediaWiki->performAction()
#20 /var/www/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#21 /var/www/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#22 /var/www/techotopia/index.php(41): MediaWiki->run()
#23 {main}