|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-06-27 03:34 UTC] karlnack at fastmail dot us
Description: ------------ Custom error handlers (registered with set_error_handler()) are passed an $errcontext parameter with an array of every variable that was in scope when the error occurred. This would be similarly useful for assert callback functions registered with assert_options(). This could presumably be passed as a fifth (optional) parameter to the assert callback function. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 19:00:02 2025 UTC |
Here's a basic example: class ErrorHandler { private $assertion; public static function enable() { // Configure errors. error_reporting(E_ALL); // Configure assertions. assert_options(ASSERT_ACTIVE, 1); assert_options(ASSERT_WARNING, 1); assert_options(ASSERT_BAIL, 0); assert_options(ASSERT_QUIET_EVAL, 0); // Register handlers. $eh = new ErrorHandler(); set_error_handler([$eh, 'handle_error'], error_reporting()); assert_options(ASSERT_CALLBACK, [$eh, 'handle_assertion']); } public function handle_assertion($file, $line, $code, $desc = null) { // Save the raw assertion code and description. // The actual assertion is handled in the error handler. $this->assertion = [$code, $desc]; } public function handle_error($errno, $errstr, $errfile, $errline, $errcontext) { if (!(error_reporting() & $errno)) { // This error code is not included in error_reporting. return; } if (!$this->assertion) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } list($code, $desc) = $this->assertion; $this->assertion = null; // Reset the assertion. // Handle the assertion here. } }