Upload
larry-ball
View
3.020
Download
5
Tags:
Embed Size (px)
DESCRIPTION
An overview of basic fundamental php debugging concepts meant to be accompanied by real world examples on a live or local web server
Citation preview
PHP DEBUGGINGBEYOND ECHO
PHP MESSAGE TYPES
• Notice – not a best coding practice
• Warning – will probably cause errors upon execution
• Error – fatal (crash)
• Occur when script is interpreted (no execution - e.g., “The white screen of death”), or at script execution (run-time error halts execution)
COMMON PHP ERROR LEVELS
Referenced by constants representing bit level integers to the interpreter
• E_ERROR – fatal run-time error (crash)
• E_WARNING – run-time warning
• E_NOTICE – run-time notice
• E_STRICT – interpretation-time notice
• E_DEPRECATED – run-time – will not work in future PHP versions
• E_ALL – all notices, warnings, and errors
DISPLAYING ERRORS
• error_reporting – sets level via constant
• Default: all except E_NOTICE
• display_errors – displays error to users (only use in development environment)
• 1 or 0 – default is 1
SETTING ERROR REPORTING AND DISPLAY
• php.ini – affects entire server (server-agnostic)
• preferred method, use phpinfo() to locate
• httpd.conf – affects only an Apache server configuration
• also requires allow override options or allow override all privileges
• .htaccess – affects directory
• also requires allow override options or allow override all privileges
• script – affects run-time
• always available, but not all configuration options are available
php.ini
.htaccess
httpd.conf
script.php
SCRIPT LEVEL ERROR MANAGEMENT
LOGGING ERRORS
• log_errors – toggle error logging
• Default: off
• log_errors_max_len – length of error message in bytes
• default: 1024
• 0 is unlimited
• error_log – full path to log file
• default: NULL (goes to server error log; not a best practice)
• set log file path outside of the web root
DISPLAYING ERRORS
• error_reporting – sets level via constant
• Default: all except E_NOTICE
• display_errors – displays error to users (only use in development environment)
• 1 or 0 – default is 1
TRIGGER_ERROR
DEBUG_BACKTRACE
• backtrace – sequence of function/method calls
• invaluable in debugging frameworks/complex structures
• returns associative array – keyed in ascending order
• lowest number - last execution
• each contains function/method, line number, file, class, object, and arguments!