From: pdontthink Date: Tue, 13 Nov 2007 00:11:15 +0000 (+0000) Subject: Adding new function that allows us to stop using the @ error suppression operator... X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=8442ecb9a9eb963c4ab2de6c09d115a46cbe9385;hp=1e09ecc2802d6b331d3f986dc705d8ae80313e4d Adding new function that allows us to stop using the @ error suppression operator but still keep notices and errors off screen. Includes two sample uses: file uploads on the compose screen and session_start(), although the latter is very noisy in both the logs and in DEVEL's on-screen developer error handler display. It might be best to add a flag to turn these errors off in the logs too. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12763 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/global.php b/functions/global.php index f470a481..1f560e89 100644 --- a/functions/global.php +++ b/functions/global.php @@ -83,6 +83,40 @@ function sqstripslashes(&$array) { } } +/** + * Squelch error output to screen (only) for the given function. + * + * This provides an alternative to the @ error-suppression + * operator where errors will not be shown in the interface + * but will show up in the server log file (assuming the + * administrator has configured PHP logging). + * + * @since 1.4.12 and 1.5.2 + * + * @param string $function The function to be executed + * @param array $args The arguments to be passed to the function + * (OPTIONAL; default no arguments) + * NOTE: The caller must take extra action if + * the function being called is supposed + * to use any of the parameters by + * reference. In the following example, + * $x is passed by reference and $y is + * passed by value to the "my_func" + * function. + * sq_call_function_suppress_errors('my_func', array(&$x, $y)); + * + * @return mixed The return value, if any, of the function being + * executed will be returned. + * + */ +function sq_call_function_suppress_errors($function, $args=NULL) { + $display_errors = ini_get('display_errors'); + ini_set('display_errors', '0'); + $ret = call_user_func_array($function, $args); + ini_set('display_errors', $display_errors); + return $ret; +} + /** * Add a variable to the session. * @param mixed $var the variable to register @@ -365,7 +399,8 @@ function sqsession_is_active() { function sqsession_start() { global $base_uri; - @session_start(); + sq_call_function_suppress_errors('session_start'); + // was: @session_start(); $session_id = session_id(); // session_starts sets the sessionid cookie buth without the httponly var diff --git a/src/compose.php b/src/compose.php index 9acb9163..29aa1504 100644 --- a/src/compose.php +++ b/src/compose.php @@ -1421,8 +1421,8 @@ function saveAttachedFiles($session) { // m_u_f works better with restricted PHP installs (safe_mode, open_basedir), // if that doesn't work, try a simple rename. - if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$fullpath)) { - if (!@rename($_FILES['attachfile']['tmp_name'], $fullpath)) { + if (!sq_call_function_suppress_errors('move_uploaded_file', array($_FILES['attachfile']['tmp_name'], $fullpath))) { + if (!sq_call_function_suppress_errors('rename', array($_FILES['attachfile']['tmp_name'], $fullpath))) { return true; } }