Databases Reference
In-Depth Information
Figure 14-1. Web page produced when running Example 14-1
}
// Function to add 19 to the received variable;
// the function receives a reference to the variable
// (note the ampersand before the variable name).
function AddNineteen_reference(&$MyVariable)
{
$MyVariable+=19;
}
?>
</table>
</body>
</html>
The output of the program is shown in Figure 14-1.
When the variable is passed by value, the function makes its own copy, and any oper-
ations it performs on the variable are limited to the function itself. When the variable
is passed by reference, any changes that the function makes (in this case, adding 19 to
the value) are seen by the main program. Note that the name of the variable used by
the function can be different from the name used by the main program when calling
the function; here, the AddNineteen_value( ) and AddNineteen_reference( ) functions
use the name $MyVariable internally.
Handling Errors in PHP
Sadly, every programmer—however experienced—makes mistakes. PHP tries to help
in finding and rectifying these mistakes by providing detailed error messages when it
detects a problem. It's useful to have PHP report detailed information on all errors
during development, but it's best to avoid displaying much of this information to the
end user in a production system. This will reduce the amount of confusion and also
hide information that an attacker could find useful.
PHP is configured through a php.ini configuration file that includes two important
directives that affect error reporting: error_reporting and display_errors . The former
controls what types of errors are trapped, and the latter controls whether error messages
are reported. When PHP is configured, display_errors is set to On and
error_reporting lists selected errors that can occur; by default, in PHP4 and PHP5, it
 
Search WWH ::




Custom Search