Created
August 22, 2012 03:26
-
-
Save ngyuki/3422054 to your computer and use it in GitHub Desktop.
[hatena 20120822] 特定のスコープでだけPHPエラーを例外としてスローするためのクラス
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 | |
class Lish_ErrorHandler_Thrown | |
{ | |
private $_original = false; | |
/** | |
* コンストラクタ | |
*/ | |
public function __construct() | |
{ | |
$this->_original = set_error_handler( | |
function($errno, $errstr, $errfile, $errline) { | |
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); | |
} | |
); | |
} | |
/** | |
* デストラクタ | |
*/ | |
public function __destruct() | |
{ | |
$this->restore(); | |
} | |
/** | |
* エラーハンドラを元に戻す | |
*/ | |
public function restore() | |
{ | |
if ($this->_original !== false) | |
{ | |
restore_error_handler(); | |
$this->_original = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment