php debugging

10
PHP DEBUGGING BEYOND ECHO

Upload: larry-ball

Post on 08-Jun-2015

3.031 views

Category:

Technology


5 download

DESCRIPTION

An overview of basic fundamental php debugging concepts meant to be accompanied by real world examples on a live or local web server

TRANSCRIPT

Page 1: Php debugging

PHP DEBUGGINGBEYOND ECHO

Page 2: Php debugging

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)

Page 3: Php debugging

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

Page 4: Php debugging

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

Page 5: Php debugging

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

Page 6: Php debugging

SCRIPT LEVEL ERROR MANAGEMENT

Page 7: Php debugging

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

Page 8: Php debugging

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

Page 9: Php debugging

TRIGGER_ERROR

Page 10: Php debugging

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!