diff --git a/functions/misc.xml b/functions/misc.xml
index 2afc6fe5b0..ed4da320b7 100644
--- a/functions/misc.xml
+++ b/functions/misc.xml
@@ -144,40 +144,18 @@ echo constant("MAXSIZE"); // same thing as the previous line
Description
- int define
+ bool definestring namemixed value
- int
+ bool
case_insensitive
- Defines a named constant, which is similar to a variable except:
-
-
-
- Constants do not have a dollar sign '$' before them;
-
-
-
-
- Constants may be accessed anywhere without regard to variable
- scoping rules;
-
-
-
-
- Constants may not be redefined or undefined once they have
- been set; and
-
-
-
-
- Constants may only evaluate to scalar values.
-
-
-
+ Defines a named constant. See the
+ section on constants
+ for more details.
The name of the constant is given by name;
@@ -186,7 +164,7 @@ echo constant("MAXSIZE"); // same thing as the previous line
The optional third parameter
case_insensitive is also available. If the
- value 1 is given, then the constant will be
+ value TRUE is given, then the constant will be
defined case-insensitive. The default behaviour is
case-sensitive; i.e. CONSTANT and Constant represent different
values.
@@ -198,12 +176,19 @@ echo constant("MAXSIZE"); // same thing as the previous line
<?php
define ("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
+echo Constant; // outputs "Constant" and issues a notice.
+
+define ("GREETING", "Hello you.",TRUE);
+echo GREETING; // outputs "Hello you."
+echo Greeting; // outputs "Hello you."
+
?>
- Define returns TRUE on success and FALSE if
+ Define returns TRUE
+ on success and FALSE if
an error occurs.
@@ -225,13 +210,14 @@ echo CONSTANT; // outputs "Hello world."
Description
- int defined
+ bool definedstring name
- Returns true if the named constant given by
- name has been defined, false otherwise.
+ Returns TRUE if the named constant given by
+ name has been defined,
+ FALSE otherwise.
Checking Constants
diff --git a/language/constants.xml b/language/constants.xml
index e37060bb06..e58e2a9ef9 100644
--- a/language/constants.xml
+++ b/language/constants.xml
@@ -2,13 +2,97 @@
Constants
- PHP defines several constants and provides a mechanism for defining
- more at run-time. Constants are much like variables, save for the
- two facts that constants must be defined using the
- define function, and that they cannot later be
- redefined to another value.
+ A constant is a identifier (name) for a simple value. As the name
+ suggests, that value cannot change during the execution of the script
+ (the magic constants __FILE__ and
+ __LINE__ are the only exception). A constant
+ is case-sensitive by default. By convention constants are always
+ uppercase.
+
+ The scope of a constant is global.
+
+
+ Syntax
+
+ You can define a constant by using the
+ define-function. Once a constant is defined,
+ it can never be changed or undefined.
+
+
+ Only scalar data (boolean, integer,
+ double and string) can be contained
+ in constants.
+
+
+ You can get the value of a constant by simply specifying its name.
+ Unlike with variables, you should not prepend
+ a constant with a $.
+ You can also use the constant-function, for
+ example if the name of the constant is variable.
+ Use get_defined_constants to get a list of
+ all defined constants.
+
+
+
+ Constants and (global) variables are in a different namespace.
+ This implies that for example TRUE and
+ $TRUE are generally different.
+
+
+
+ If you use an undefined constant, PHP assumes that you mean
+ the name of the constant itself. A
+ notice will be issued
+ when this happens. Use the defined-function if
+ you want to know if a constant is set.
+
+
+ This are the differences with variables:
+
+
+
+ Constants do not have a dollar sign ($) before them;
+
+
+
+
+ Constants may be defined and accessed anywhere without regard to variable
+ scoping rules;
+
+
+
+
+ Constants may not be redefined or undefined once they have
+ been set; and
+
+
+
+
+ Constants may only evaluate to scalar values.
+
+
+
+
+
+
+
+ Defining Constants
+
+<?php
+define("CONSTANT", "Hello world.");
+echo CONSTANT; // outputs "Hello world."
+echo Constant; // outputs "Constant" and issues a notice.
+?>
+
+
+
+
+
+
+
+ Predefined constants
The predefined constants (always available) are:
@@ -63,7 +147,7 @@
TRUE (case-insensitive)
- A true value.
+ A true value (see the boolean type).
@@ -72,7 +156,16 @@
FALSE (case-insensitive)
- A false value.
+ A false value (see the boolean type).
+
+
+
+
+
+ NULL (case-insensitive)
+
+
+ A null value (see the null type).
@@ -114,7 +207,7 @@
Something happened which may or may not be an error. Execution
- continues. Examples include using an unquoted string as a hash
+ continues. Examples include using an unquoted string as a array
index, or accessing a variable which has not been set.
@@ -135,29 +228,10 @@
- The E_* constants are typically used with the
- error_reporting function for setting the
- error reporting level. See all these constants at
- Error handling.
-
-
-
- You can define additional constants using the
- define function.
-
-
- Note that these are constants, not C-style macros; only valid
- scalar data may be represented by a constant.
-
-
- Defining Constants
-
-<?php
-define("CONSTANT", "Hello world.");
-echo CONSTANT; // outputs "Hello world."
-?>
-
-
+ The E_* constants are typically used with the
+ error_reporting function for setting the
+ error reporting level. See all these constants at
+ Error handling.
Using __FILE__ and __LINE__
@@ -170,9 +244,10 @@ function report_error($file, $line, $message) {
report_error(__FILE__,__LINE__, "Something went wrong!");
?>
-
-
-
+
+
+
+