3
我想弄清楚是否有一個好的或更好的方法來處理PHP中的錯誤,而不是我在下面做的。如果parse_ini_file
呼叫有問題,我想拋出異常。這有效,但有沒有更好的方法來處理錯誤?作爲例外處理錯誤。最好的方法?
public static function loadConfig($file, $type)
{
if (!file_exists($file))
{
require_once 'Asra/Core/Exception.php';
throw new Asra_Core_Exception("{$type} file was not present at specified location: {$file}");
}
// -- clear the error
self::$__error = null;
// -- set the error handler function temporarily
set_error_handler(array('Asra_Core_Loader', '__loadConfigError'));
// -- do the parse
$parse = parse_ini_file($file, true);
// -- restore handler
restore_error_handler();
if (!is_array($parse) || is_null($parse) || !is_null(self::$__error))
{
require_once 'Asra/Core/Exception.php';
throw new Asra_Core_Exception("{$type} file at {$file} appears to be
}
}
的__ loadConfigError
功能剛剛設置__error
到錯誤字符串:
private static function __loadConfigError($errno, $errstr, $errfile, $errline)
{
self::$__error = $errstr;
}
謝謝!