*/ # Syntax # comment Description The # PHP element, which is commonly referred to as a "UNIX shell-style comment," enables programmers to include one-line comments in their code.. __
Trang 1must appear on only one line and after the // indicator Here is a quick example of using this method of commenting:
// C, Java, and JavaScript programmers should understand how this
method works
// in the PHP programming language
/* */
Syntax
/*
comment
*/
Description
The /* */ PHP element is another method of defining a comment in the PHP language This method enables you to write comments that span multiple lines, so you can format your comments without using multiple // instances Be careful when using this syntax and avoid nesting any comments Here is a quick example of using this method of commenting:
/*
Title: Understanding comments
Description: In your comments you may wish to have comments that span more than one line If so, this is the method you should use
*/
#
Syntax
# comment
Description
The # PHP element, which is commonly referred to as a "UNIX shell-style comment," enables programmers to include one-line comments in their code This particular style is the same as the one seen in UNIX shells and, likewise, comment must appear
on only one line and after the # indicator Here is a quick example of using this method of commenting:
Trang 2# You Perl programmers should understand how this method works
# in the PHP programming language
Constants
Constants are a way for a programmer to define constant values for variables by using the define() method at runtime The difference between these variables and other variables that you might have in your code is that these cannot be changed
In this section of the book, we look at several predefined PHP constants that reflect the environment in which the PHP interpreter is running
FILE
Syntax
FILE
Description
The FILE constant reflects the name of the current file being parsed by the PHP interpreter
LINE
Syntax
LINE
Description
The LINE constant reflects the line number of the current file being parsed by the PHP interpreter
E_ERROR
Syntax
E_ERROR
Description
Trang 3The E_ERROR constant contains a nonparsing and nonrecoverable error that has occurred Additionally, you can use the error_reporting() function to specify the level of error reports you want out of this function
E_NOTICE
Syntax
E_NOTICE
Description
The E_NOTICE constant contains what may or may not be an error in your PHP code, but either way, it does not prevent the code from completing execution Additionally, you can use the error_reporting() function to specify the level of error reports you want out of this function
E_PARSE
Syntax
E_PARSE
Description
The E_PARSE constant reflects the fact that the PHP parser failed because of a syntax problem and cannot recover Additionally, you can use the error_reporting() function to specify the level of error reports you want out of this function
E_WARNING
Syntax
E_WARNING
Description
The E_WARNING constant contains an error in your PHP code, but does not prevent the code from completing execution Additionally, you can use the error_reporting() function to specify the level of error reports you want out of this function
Trang 4PHP_OS
Syntax
PHP_OS
Description
The PHP_OS constant reflects the name of the operating system that is currently parsing and interpreting the PHP code If you are running scripts across multiple platforms, this enables you to check the operating system before performing any system-specific tasks
PHP_VERSION
Syntax
PHP_VERSION
Description
The PHP_VERSION constant contains a string that reflects the exact version of the PHP interpreter
FALSE
Syntax
FALSE
Description
The FALSE constant reflects a Boolean false value
TRUE
Syntax
TRUE
Trang 5Description
The TRUE constant reflects a Boolean true value
Control Structures and Statements
Control structures and statements are items that all programmers use to control the flow of their programs This includes most looping commands, such as if or while statements, and other commands, such as break and continue, that can be used to control the program execution in the body of a control structure
break
Syntax
break [int num]
Description
The break statement enables you to break out of an if, switch, or while control structure The optional num value can be used to tell the parser how many control
structures to break out of For instance, if you used a break statement inside an if statement that was inside a while statement itself, you could use break 2 to break out of both statements Using break 1, which is the default implied value when not passed, would simply break you out of the if statement
if($num == 5){
// do something here
if($string == "go"){
// do more here
break 2; // breaks outside of both if statements
}
}
// the break 2 will start back here if executed
continue
Syntax
continue [int num]
Description