• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Errors
 

Errors

on

  • 356 views

 

Statistics

Views

Total Views
356
Views on SlideShare
356
Embed Views
0

Actions

Likes
0
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Errors Errors Presentation Transcript

    • Errors
    • Fatal Errors Calling undefined functions require() when the file does not exist
    • Fatal Errors - example <?php //call a non-existent function test_function(); ?> Output Fatal error: Call to undefined function test_function() in /var/www/website/html/index.php on line 4
    • Warnings and Notices Undefined variables Referencing non-existent array keys Typos Wrong variable types passed to functions
    • Warnings and Notices - Example <?php //initialise the string variable $string = ‘a string’; //explode() a string explode($string); ?> Output: Warning: Wrong parameter count for explode() in /var/www/website.com/html/index.php on line 6
    • Database Errors Can’t connect to a database Can’t access a table Broken query
    • Fatal Errors Usually displays a blank page Error messages are hidden from users, but are logged
    • Warnings and Notices Page will display, but may stop executing prematurely Error messages are hidden from the user, but are logged Affects performance & user experience
    • Database Errors If the database can’t connect, it returns a fatal error If a table/field can’t or found, or a query can’t be executed, it returns a warning
    • Better Error Handling Define a custom error handler: set_error_handler(‘function_name’); Accept five arguments:- • error type • message • file name • line number • context
    • Better Error Handling - continued Do whatever you want to within the function – Output a message to the user – Send an email to someone dependent on the error Errors are still logged Should be built into base systems Does not work for a fatal error.
    • Better Error Handling - continued register_shutdown_function() This function will be called once a fatal error has happened However, it is executed after PHP has finished processing every single script Be careful with it!