Skip to content

Instantly share code, notes, and snippets.

@ngyuki
Created August 22, 2012 03:26
Show Gist options
  • Save ngyuki/3422054 to your computer and use it in GitHub Desktop.
Save ngyuki/3422054 to your computer and use it in GitHub Desktop.
[hatena 20120822] 特定のスコープでだけPHPエラーを例外としてスローするためのクラス
<?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