|
@@ -26,16 +26,18 @@ class Silencer
|
|
|
/**
|
|
|
* Suppresses given mask or errors.
|
|
|
*
|
|
|
- * @param int|null $mask Error levels to suppress, default value NULL indicates all warnings and below.
|
|
|
- * @return int The old error reporting level.
|
|
|
+ * @param int|null $mask Error levels to suppress, default value NULL indicates all warnings and below.
|
|
|
+ * @return int The old error reporting level.
|
|
|
*/
|
|
|
public static function suppress($mask = null)
|
|
|
{
|
|
|
if (!isset($mask)) {
|
|
|
$mask = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_DEPRECATED | E_USER_DEPRECATED | E_STRICT;
|
|
|
}
|
|
|
- array_push(self::$stack, $old = error_reporting());
|
|
|
+ $old = error_reporting();
|
|
|
+ array_push(self::$stack, $old);
|
|
|
error_reporting($old & ~$mask);
|
|
|
+
|
|
|
return $old;
|
|
|
}
|
|
|
|
|
@@ -44,8 +46,9 @@ class Silencer
|
|
|
*/
|
|
|
public static function restore()
|
|
|
{
|
|
|
- if (!empty(self::$stack))
|
|
|
+ if (!empty(self::$stack)) {
|
|
|
error_reporting(array_pop(self::$stack));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -53,9 +56,9 @@ class Silencer
|
|
|
*
|
|
|
* Future improvement: when PHP requirements are raised add Callable type hint (5.4) and variadic parameters (5.6)
|
|
|
*
|
|
|
- * @param callable $callable Function to execute.
|
|
|
- * @return mixed Return value of the callback.
|
|
|
+ * @param callable $callable Function to execute.
|
|
|
* @throws \Exception Any exceptions from the callback are rethrown.
|
|
|
+ * @return mixed Return value of the callback.
|
|
|
*/
|
|
|
public static function call($callable /*, ...$parameters */)
|
|
|
{
|
|
@@ -63,11 +66,12 @@ class Silencer
|
|
|
self::suppress();
|
|
|
$result = call_user_func_array($callable, array_slice(func_get_args(), 1));
|
|
|
self::restore();
|
|
|
+
|
|
|
return $result;
|
|
|
- } catch(\Exception $e) {
|
|
|
+ } catch (\Exception $e) {
|
|
|
// Use a finally block for this when requirements are raised to PHP 5.5
|
|
|
self::restore();
|
|
|
throw $e;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|