Any PHP scripting language is created using consecutive statements. A statement can be an assignment statement, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements often end with a semicolon (;). In addition, using volume support, a group of statements can be compressed so that statements can be grouped into statement groups. A statement group is a statement about itself. The different statement types are described in this chapter.
Constants
PHP defines some constants to provide structures to enable it to define more types at runtime. Constants and variables are very similar, but their syntax is slightly different.
The predefined constants are __FILE__ and __LINE__. When processing them, you will find that they match the file name and line number. Please refer to the following example:
Example 6-1. Using __FILE__ and __LINE__ //Use __FILE__ and __LINE__
function report_error($file, $line, $message) {
echo "An error occurred in $file on line $line: $message.";
}
report_error(__FILE__,__LINE__, "Something went wrong!");
?>
You can define other constants using the functions define() and undefine().
Example 6-2. Defining Constants // Defining constants
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
undefine ("CONSTANT");
?>