Last active
August 29, 2015 14:04
-
-
Save olimortimer/aade89e7e263f22069f5 to your computer and use it in GitHub Desktop.
PHP: Catch script failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Multiple ways of registering a function for execution on shutdown | |
// Class method | |
public function __construct() { | |
register_shutdown_function(array($this, 'scriptFailure')); | |
} | |
// Non-class method | |
register_shutdown_function('scriptFailure'); | |
// Anonymous function | |
register_shutdown_function(function() { | |
if($error = error_get_last()) mail('developer@email.com', 'Script Failure', print_r($error, true)); | |
}); | |
// Function to catch and email the error | |
private function scriptFailure() { | |
if($error = error_get_last()) mail('developer@email.com', 'Script Failure', print_r($error, true)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment