Errors
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
413
On Slideshare
413
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
3
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Errors
  • 2. Fatal Errors Calling undefined functions require() when the file does not exist
  • 3. 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
  • 4. Warnings and Notices Undefined variables Referencing non-existent array keys Typos Wrong variable types passed to functions
  • 5. 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
  • 6. Database Errors Can’t connect to a database Can’t access a table Broken query
  • 7. Fatal Errors Usually displays a blank page Error messages are hidden from users, but are logged
  • 8. 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
  • 9. 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
  • 10. Better Error Handling Define a custom error handler: set_error_handler(‘function_name’); Accept five arguments:- • error type • message • file name • line number • context
  • 11. 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.
  • 12. 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!