Errors

521 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
521
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Errors

  1. 1. Errors
  2. 2. Fatal Errors Calling undefined functions require() when the file does not exist
  3. 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. 4. Warnings and Notices Undefined variables Referencing non-existent array keys Typos Wrong variable types passed to functions
  5. 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. 6. Database Errors Can’t connect to a database Can’t access a table Broken query
  7. 7. Fatal Errors Usually displays a blank page Error messages are hidden from users, but are logged
  8. 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. 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. 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. 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. 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!

×