- every PHP script is made up of statements.
- each statement must be terminated with a semicolon.
Example:
some_instruction();
$variable = 'value';
Note:
The last instruction before a closing tag does not require a semicolon, but it is advisable to always terminate an instruction with a semicolon.Comments
Types of PHP comments:
// Single line comment
# Single line comment
/* Multi-line
comment
*//**
* API Documentation Example
*
* @param string $bar
*/
function foo($bar) { }
Note:
Because the closing tag?> will also end a comment, code like: // Do not show this ?> or this
will output:
or this
- because the single line comment was terminated by
?> - Normally, a single line comment should be terminated with a newline (
\r, \nor\r\n)
Whitespace
PHP is whitespace-insentive, except with this few limitations:
- You cannot have any whitesapce between
<?andphp - You cannot break apart keywords
ex.whi le, fo r,andfunct ion - You cannot break apart variable names and function names
ex.$var nameandfunction foo bar()
Code Block
A series of statements enclosed between two braces:
{
// some comments
f(); // a function call
}- used in creating groups of script lines that must all be executed under specific circumstances, such as a function call or a conditional statement.
- code blocks can be nested.
Language Constructs
Elements that are built-into the language that follow specific rules.
Ex.
echo 10; // will output 10
print (10); // will also output 10
exit(); // terminate the script and either output a string or return a numeric status
die(); // an alias of exit()
Note:
echo is not a function and therefore does not have a return value
No comments:
Post a Comment