Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

constant may never be used on the left side of an assignment operator. Constants ignore
scope and are therefore visible inside functions without the use of the global statement.


Although it is not necessary, it is customary to name constants exclusively with capital
letters. This helps make them stand out in your script, as in Listing 2.6.


Listing 2.6 Using a Constant


PHP creates several constants upon startup. PHP_VERSION contains the version of PHP
running the script. TRUE is set to 1. FALSE is set to 0. PHP_OS describes the operating
system. E_ERROR, E_WARNING, E_NOTICE, E_PARSE, E_ALL are for use with the
error_reporting function. You can also use FILE and LINE to get the name
of the executing script and the line number, respectively. The value of pi is stored in the
constant M_PI. Some extensions create constants, too.


Operators


An operator is a symbol that tells PHP to perform a mathematical or logical operation.
Some operators expect two arguments, some only one. Most operators fall into three
categories: arithmetic, logical, and bitwise. There are some exceptions, however. Table
2.4 lists the arithmetic operators.


Table 2.4. Arithmetic Operators
Operator Operation It Performs


  • (^) Addition



  • (^) Subtraction and Negation



  • (^) Multiplication
    / (^) Division
    % (^) Modulo Division

Free download pdf