Coding issues.
Information
none
include()
|
include() and require() are identical in every way except how they handle failure.
include() produces a Warning and continues with the processing of the page.
Example:
<?php
include('file.php'); /* file.php does not exist */
?>
|
require()
|
require() and include() are identical in every way except how they handle failure.
require() produces a Fatal Error which halts the processing of the page.
Example:
<?php
require('file.php'); /* file.php does not exist */
?>
|
.
|
Concatenate operator.
It concatenate strings.
Example:
<?php
$firstname = 'John';
$lastname = 'Smith';
echo $firstname . ' ' . $lastname;
?>
|
@
|
Error control operator.
When prepended to an expression any error messages that might be generated by that
expression will be ignored.
Example:
<?php
@include('file.php');
?>
|
global
|
Variables have a single scope which includes required and included files.
Any variables in user-defined functions have a local function scope.
Example 1:
File test.inc:
<?php
echo $a . ' world';
?>
File main.php
<?php
$a = 'hello'; /* global scope */
function showMessage() {
echo '<br />';
echo $a; /* reference to local scope variable */
}
include('test.inc');
showMessage();
?>
Example 1 shows only:
hello world
Example 2:
File test.inc:
<?php
echo $a . ' world';
?>
File main.php
<?php
$a = 'hello'; /* global scope */
function showMessage() {
global $a;
echo '<br />';
echo $a; /* reference to local scope variable */
}
include('test.inc');
showMessage();
?>
Example 2 shows:
hello world
hello
|
|