Have Horde handle PHP legacy error handling.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 30 Nov 2010 19:19:43 +0000 (12:19 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 30 Nov 2010 20:45:39 +0000 (13:45 -0700)
First - no need to use error_reporting() wrapper anymore - my tests
indicate that as of PHP 5.3, using @foo() is twice as fast.

Next, have all error messages be caught by Horde.  For now, this means
all PHP warnings are output to the Horde DEBUG log rather than to the
screen.  We can play with the various output options in
Horde::errorHandler().

Still need to go through and remove "@" from many function calls.  These
suppressions can result in the WSOD and make for difficult debugging.
Going forward, we should only be concerned with suppressing warnings
that we know aren't critical (e.g. unserialize(), htmlspecialchars()).

21 files changed:
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Core/Log/Logger.php
framework/Db/lib/Horde/Db/Adapter/Mysql.php
framework/Db/lib/Horde/Db/Adapter/Mysqli.php
framework/Db/lib/Horde/Db/Adapter/Pdo/Base.php
framework/Feed/lib/Horde/Feed/Entry/Atom.php
framework/Image/lib/Horde/Image/Gd.php
framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php
framework/Imap_Client/lib/Horde/Imap/Client/Utf7imap.php
framework/Memcache/lib/Horde/Memcache.php
framework/Text_Filter/lib/Horde/Text/Filter/Text2html.php
framework/Util/lib/Horde/String.php
framework/Xml_Element/lib/Horde/Xml/Element.php
horde/docs/CODING_STANDARDS
horde/lib/core.php
imp/config/hooks.php.dist
imp/lib/Compose.php
imp/lib/Ui/Mailbox.php
kronolith/lib/Event.php

index 632fa63..9261e50 100644 (file)
@@ -152,7 +152,7 @@ HTML;
     }
 
     /**
-     * Log deprecated errors.
+     * PHP legacy error handling (non-Exceptions).
      *
      * @param integer $errno     See set_error_handler().
      * @param string $errstr     See set_error_handler().
@@ -160,8 +160,8 @@ HTML;
      * @param integer $errline   See set_error_handler().
      * @param array $errcontext  See set_error_handler().
      */
-    static public function logDeprecated($errno, $errstr, $errfile, $errline,
-                                         $errcontext)
+    static public function errorHandler($errno, $errstr, $errfile, $errline,
+                                        $errcontext)
     {
         if (class_exists('Horde_Log')) {
             try {
index 6d62ad5..cfb0e71 100644 (file)
@@ -60,9 +60,7 @@ class Horde_Core_Log_Logger extends Horde_Log_Logger
                 $text = $event->getMessage();
                 if (!empty($userinfo)) {
                     if (is_array($userinfo)) {
-                        $old_error = error_reporting(0);
-                        $userinfo = implode(', ', $userinfo);
-                        error_reporting($old_error);
+                        $userinfo = @implode(', ', $userinfo);
                     }
                     $text .= ': ' . $userinfo;
                 }
index 2ad4ccc..97e22fd 100644 (file)
@@ -85,11 +85,8 @@ class Horde_Db_Adapter_Mysql extends Horde_Db_Adapter_Base
 
         $config = $this->_parseConfig();
 
-        $oldErrorReporting = error_reporting(0);
         $oldTrackErrors = ini_set('track_errors', 1);
-        $mysql = mysql_connect(
-            $config['host'], $config['username'], $config['password']);
-        error_reporting($oldErrorReporting);
+        $mysql = @mysql_connect($config['host'], $config['username'], $config['password']);
         ini_set('track_errors', $oldTrackErrors);
 
         if (!$mysql) {
index 185e6c3..a838b12 100644 (file)
@@ -131,11 +131,9 @@ class Horde_Db_Adapter_Mysqli extends Horde_Db_Adapter_Base
                 $config['host'], $config['username'], $config['password'],
                 $config['dbname'], $config['port'], $config['socket']);
         } else {
-            $oldErrorReporting = error_reporting(0);
-            $mysqli = new mysqli(
+            $mysqli = @new mysqli(
                 $config['host'], $config['username'], $config['password'],
                 $config['dbname'], $config['port'], $config['socket']);
-            error_reporting($oldErrorReporting);
         }
         if (mysqli_connect_errno()) {
             throw new Horde_Db_Exception('Connect failed: (' . mysqli_connect_errno() . ') ' . mysqli_connect_error(), mysqli_connect_errno());
index 8868896..4999560 100644 (file)
@@ -38,12 +38,9 @@ abstract class Horde_Db_Adapter_Pdo_Base extends Horde_Db_Adapter_Base
 
         list($dsn, $user, $pass) = $this->_parseConfig();
 
-        $oldErrorReporting = error_reporting(0);
         try {
-            $pdo = new PDO($dsn, $user, $pass);
-            error_reporting($oldErrorReporting);
+            $pdo = @new PDO($dsn, $user, $pass);
         } catch (PDOException $e) {
-            error_reporting($oldErrorReporting);
             $msg = "Could not instantiate PDO with DSN \"$dsn\".  PDOException: "
                 . $e->getMessage();
             throw new Horde_Db_Exception($msg);
index 8d76471..771fc00 100644 (file)
@@ -121,9 +121,7 @@ class Horde_Feed_Entry_Atom extends Horde_Feed_Entry_Base
         // Update internal properties using the response body.
         $body = $response->getBody();
         $newEntry = new DOMDocument;
-        $e = error_reporting(0);
-        $parsed = $newEntry->loadXML($body);
-        error_reporting($e);
+        $parsed = @$newEntry->loadXML($body);
         if (!$parsed) {
             throw new Horde_Feed_Exception('DOMDocument cannot parse XML: ', error_get_last());
         }
index 4bf3193..d454c3f 100644 (file)
@@ -778,13 +778,10 @@ class Horde_Image_Gd extends Horde_Image_Base
     {
         unset($php_errormsg);
         $track = ini_set('track_errors', 1);
-        $error_mask = E_ALL & ~E_WARNING & ~E_NOTICE;
-        $old_reporting = error_reporting($error_mask);
-        $result = call_user_func_array($function, $params);
+        $result = @call_user_func_array($function, $params);
         if ($track !== false) {
             ini_set('track_errors', $track);
         }
-        error_reporting($old_reporting);
         if (!empty($php_errormsg)) {
             $error_msg = $php_errormsg;
             throw new Horde_Image_Exception($error_msg);
index b71934b..6bf44cb 100644 (file)
@@ -146,11 +146,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         // Already guaranteed to be logged in here.
 
-        $old_error = error_reporting(0);
-        $res = imap_ping($this->_stream);
-        error_reporting($old_error);
-
-        if ($res === false) {
+        if (@imap_ping($this->_stream) === false) {
             $this->_exception('Received error from IMAP server when sending a NOOP command: ' . imap_last_error());
         }
     }
@@ -194,9 +190,8 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
         $mask = ($this->_service == 'pop3') ? 0 : OP_HALFOPEN;
 
-        $old_error = error_reporting(0);
         if (version_compare(PHP_VERSION, '5.2.1') != -1) {
-            $res = imap_open($this->_connString(), $this->_params['username'], $this->getParam('password'), $mask, $this->_params['retries']);
+            $res = @imap_open($this->_connString(), $this->_params['username'], $this->getParam('password'), $mask, $this->_params['retries']);
         } else {
             while (($res === false) &&
                    !strstr(strtolower(imap_last_error()), 'login failure') &&
@@ -204,10 +199,9 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                 if ($i != 0) {
                     sleep(1);
                 }
-                $res = imap_open($this->_connString(), $this->_params['username'], $this->getParam('password'), $mask);
+                $res = @imap_open($this->_connString(), $this->_params['username'], $this->getParam('password'), $mask);
             }
         }
-        error_reporting($old_error);
 
         if ($res === false) {
             $this->_exception('Could not authenticate to IMAP server: ' . imap_last_error());
@@ -316,13 +310,9 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         $this->login();
         $flag = ($mode == Horde_Imap_Client::OPEN_READONLY) ? OP_READONLY : 0;
 
-        $old_error = error_reporting(0);
-        if (version_compare(PHP_VERSION, '5.2.1') != -1) {
-            $res = imap_reopen($this->_stream, $this->_connString($mailbox), $flag, $this->_params['retries']);
-        } else {
-            $res = imap_reopen($this->_stream, $this->_connString($mailbox), $flag);
-        }
-        error_reporting($old_error);
+        $res = (version_compare(PHP_VERSION, '5.2.1') != -1)
+            ? @imap_reopen($this->_stream, $this->_connString($mailbox), $flag, $this->_params['retries'])
+            : @imap_reopen($this->_stream, $this->_connString($mailbox), $flag);
 
         if ($res === false) {
             $this->_exception('Could not open mailbox "' . $mailbox . '": ' . imap_last_error());
@@ -346,11 +336,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
         $this->login();
 
-        $old_error = error_reporting(0);
-        $res = imap_createmailbox($this->_stream, $this->_connString($mailbox));
-        error_reporting($old_error);
-
-        if ($res === false) {
+        if (@imap_createmailbox($this->_stream, $this->_connString($mailbox)) === false) {
             $this->_exception('Could not create mailbox "' . $mailbox . '": ' . imap_last_error());
         }
     }
@@ -366,11 +352,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         $this->login();
 
-        $old_error = error_reporting(0);
-        $res = imap_deletemailbox($this->_stream, $this->_connString($mailbox));
-        error_reporting($old_error);
-
-        if ($res === false) {
+        if (@imap_deletemailbox($this->_stream, $this->_connString($mailbox) === false)) {
             $this->_exception('Could not delete mailbox "' . $mailbox . '": ' . imap_last_error());
         }
     }
@@ -387,11 +369,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         $this->login();
 
-        $old_error = error_reporting(0);
-        $res = imap_renamemailbox($this->_stream, $this->_connString($old), $this->_connString($new));
-        error_reporting($old_error);
-
-        if ($res === false) {
+        if (@imap_renamemailbox($this->_stream, $this->_connString($old), $this->_connString($new)) === false) {
             $this->_exception('Could not rename mailbox "' . $old . '": ' . imap_last_error());
         }
     }
@@ -408,13 +386,9 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         $this->login();
 
-        $old_error = error_reporting(0);
-        if ($subscribe) {
-            $res = imap_subscribe($this->_stream, $this->_connString($mailbox));
-        } else {
-            $res = imap_unsubscribe($this->_stream, $this->_connString($mailbox));
-        }
-        error_reporting($old_error);
+        $res = $subscribe
+            ? @imap_subscribe($this->_stream, $this->_connString($mailbox))
+            : @imap_unsubscribe($this->_stream, $this->_connString($mailbox));
 
         if ($res === false) {
             $this->_exception('Could not ' . ($subscribe ? 'subscribe' : 'unsubscribe') . ' to mailbox "' . $mailbox . '": ' . imap_last_error());
@@ -491,9 +465,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
             LATT_HASNOCHILDREN => '\\hasnochildren'
         );
 
-        $old_error = error_reporting(0);
-        $res = imap_getmailboxes($this->_stream, $this->_connString(), $pattern);
-        error_reporting($old_error);
+        $res = @imap_getmailboxes($this->_stream, $this->_connString(), $pattern);
 
         $mboxes = array();
         while (list(,$val) = each($res)) {
@@ -553,13 +525,9 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
         $mboxes = array();
 
-        $old_error = error_reporting(0);
-        if ($mode != Horde_Imap_Client::MBOX_ALL) {
-            $res = imap_list($this->_stream, $this->_connString(), $pattern);
-        } else {
-            $res = imap_lsub($this->_stream, $this->_connString(), $pattern);
-        }
-        error_reporting($old_error);
+        $res = ($mode != Horde_Imap_Client::MBOX_ALL)
+            ? @imap_list($this->_stream, $this->_connString(), $pattern)
+            : @imap_lsub($this->_stream, $this->_connString(), $pattern);
 
         if (is_array($res)) {
             while (list(,$val) = each($res)) {
@@ -663,10 +631,11 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         }
 
         while (list(,$val) = each($data)) {
-            $old_error = error_reporting(0);
-            $text = is_resource($val['data']) ? stream_get_contents($val['data']) : $val['data'];
-            $res = imap_append($this->_stream, $this->_connString($mailbox), $this->utils->removeBareNewlines($text), empty($val['flags']) ? null : implode(' ', $val['flags']));
-            error_reporting($old_error);
+            $text = is_resource($val['data'])
+                ? stream_get_contents($val['data'])
+                : $val['data'];
+
+            $res = @imap_append($this->_stream, $this->_connString($mailbox), $this->utils->removeBareNewlines($text), empty($val['flags']) ? null : implode(' ', $val['flags']));
 
             if ($res === false) {
                 if (!empty($options['create'])) {
@@ -690,11 +659,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         // Already guaranteed to be logged in here.
 
-        $old_error = error_reporting(0);
-        $res = imap_check($this->_stream);
-        error_reporting($old_error);
-
-        if ($res === false) {
+        if (@imap_check($this->_stream) === false) {
             $this->_exception('Received error from IMAP server when sending a CHECK command: ' . imap_last_error());
         }
     }
@@ -737,9 +702,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         }
 
         if (empty($options['ids'])) {
-            $old_error = error_reporting(0);
-            imap_expunge($this->_stream);
-            error_reporting($old_error);
+            @imap_expunge($this->_stream);
             return $msg_list ? $ids['match'] : null;
         }
 
@@ -769,9 +732,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
             }
         }
 
-        $old_error = error_reporting(0);
-        imap_expunge($this->_stream);
-        error_reporting($old_error);
+        @imap_expunge($this->_stream);
 
         if (!empty($unflag)) {
             $this->store($this->_selected, array('add' => array('\\deleted'), 'ids' => $unflag, 'sequence' => $use_seq));
@@ -904,9 +865,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
         $use_seq = !empty($options['sequence']);
 
-        $old_error = error_reporting(0);
-        $ob = imap_thread($this->_stream, $use_seq ? 0 : SE_UID);
-        error_reporting($old_error);
+        $ob = @imap_thread($this->_stream, $use_seq ? 0 : SE_UID);
 
         if (empty($ob)) {
             return array();
@@ -995,8 +954,6 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         $err = false;
         $hdrinfo = $overview = null;
 
-        $old_error = error_reporting(0);
-
         // These options are not supported by this driver.
         if (!empty($options['changedsince']) ||
             (reset($options['ids']) == Horde_Imap_Client::USE_SEARCHRES)) {
@@ -1005,7 +962,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
         if (empty($options['ids'])) {
             $seq = '1:*';
-            $options['ids'] = range(1, imap_num_msg($this->_stream));
+            $options['ids'] = range(1, @imap_num_msg($this->_stream));
         } else {
             $seq = $this->utils->toSequenceString($options['ids']);
         }
@@ -1021,7 +978,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
             case Horde_Imap_Client::FETCH_STRUCTURE:
                 // 'noext' has no effect in this driver
                 foreach ($options['ids'] as $id) {
-                    $structure = imap_fetchstructure($this->_stream, $id, empty($options['sequence']) ? FT_UID : 0);
+                    $structure = @imap_fetchstructure($this->_stream, $id, empty($options['sequence']) ? FT_UID : 0);
                     if (!$structure) {
                         $err = true;
                         break 2;
@@ -1033,8 +990,8 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
             case Horde_Imap_Client::FETCH_FULLMSG:
                 foreach ($options['ids'] as $id) {
-                    $tmp = imap_fetchheader($this->_stream, $id, (empty($options['sequence']) ? FT_UID : 0) | FT_PREFETCHTEXT) .
-                           imap_body($this->_stream, $id, (empty($options['sequence']) ? FT_UID : 0) | (empty($c_val['peek']) ? 0 : FT_PEEK));
+                    $tmp = @imap_fetchheader($this->_stream, $id, (empty($options['sequence']) ? FT_UID : 0) | FT_PREFETCHTEXT) .
+                           @imap_body($this->_stream, $id, (empty($options['sequence']) ? FT_UID : 0) | (empty($c_val['peek']) ? 0 : FT_PEEK));
                     if (isset($c_val['start']) && !empty($c_val['length'])) {
                         $ret[$id]['fullmsg'] = substr($tmp, $c_val['start'], $c_val['length']);
                     } else {
@@ -1075,7 +1032,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                         if (!isset($ret[$id][$label])) {
                             $ret[$id][$label] = array();
                         }
-                        $tmp = imap_fetchbody($this->_stream, $id, $header_key, empty($options['sequence']) ? FT_UID : 0);
+                        $tmp = @imap_fetchbody($this->_stream, $id, $header_key, empty($options['sequence']) ? FT_UID : 0);
 
                         if (isset($val['start']) && !empty($val['length'])) {
                             $tmp = substr($tmp, $val['start'], $val['length']);
@@ -1107,7 +1064,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                             $ret[$id]['bodytext'] = array();
                         }
                         if ($use_imapbody) {
-                            $tmp = imap_body($this->_stream, $id, (empty($options['sequence']) ? FT_UID : 0) | (empty($val['peek']) ? 0 : FT_PEEK));
+                            $tmp = @imap_body($this->_stream, $id, (empty($options['sequence']) ? FT_UID : 0) | (empty($val['peek']) ? 0 : FT_PEEK));
                             if (isset($val['start']) && !empty($val['length'])) {
                                 $ret[$id]['bodytext'][0] = substr($tmp, $val['start'], $val['length']);
                             } else {
@@ -1119,8 +1076,8 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                              * is download the header of the part, determine
                              * the length, and then remove that info from the
                              * beginning of the imap_fetchbody() data. */
-                            $hdr_len = strlen(imap_fetchbody($this->_stream, $id, $val['id'] . '.0', (empty($options['sequence']) ? FT_UID : 0)));
-                            $tmp = substr(imap_fetchbody($this->_stream, $id, $val['id'], (empty($options['sequence']) ? FT_UID : 0)), $hdr_len);
+                            $hdr_len = strlen(@imap_fetchbody($this->_stream, $id, $val['id'] . '.0', (empty($options['sequence']) ? FT_UID : 0)));
+                            $tmp = substr(@imap_fetchbody($this->_stream, $id, $val['id'], (empty($options['sequence']) ? FT_UID : 0)), $hdr_len);
                             if (isset($val['start']) && !empty($val['length'])) {
                                 $ret[$id]['bodytext'][$val['id']] = substr($tmp, $val['start'], $val['length']);
                             } else {
@@ -1172,7 +1129,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                 if (is_null($hdrinfo)) {
                     $hdrinfo = array();
                     foreach ($options['ids'] as $id) {
-                        $hdrinfo[$id] = imap_headerinfo($this->_stream, empty($options['sequence']) ? imap_msgno($this->_stream, $id) : $id);
+                        $hdrinfo[$id] = @imap_headerinfo($this->_stream, empty($options['sequence']) ? @imap_msgno($this->_stream, $id) : $id);
                         if (!$hdrinfo[$id]) {
                             $err = true;
                             break 2;
@@ -1211,7 +1168,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
             case Horde_Imap_Client::FETCH_FLAGS:
                 if (is_null($overview)) {
-                    $overview = imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
+                    $overview = @imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
                     if (!$overview) {
                         $err = true;
                         break 2;
@@ -1233,7 +1190,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                 if (is_null($hdrinfo)) {
                     $hdrinfo = array();
                     foreach ($options['ids'] as $id) {
-                        $hdrinfo[$id] = imap_headerinfo($this->_stream, empty($options['sequence']) ? imap_msgno($this->_stream, $id) : $id);
+                        $hdrinfo[$id] = @imap_headerinfo($this->_stream, empty($options['sequence']) ? @imap_msgno($this->_stream, $id) : $id);
                         if (!$hdrinfo[$id]) {
                             $err = true;
                             break 2;
@@ -1253,7 +1210,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                     }
                 } else {
                     if (is_null($overview)) {
-                        $overview = imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
+                        $overview = @imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
                         if (!$overview) {
                             $err = true;
                             break;
@@ -1272,7 +1229,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                     }
                 } else {
                     if (is_null($overview)) {
-                        $overview = imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
+                        $overview = @imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
                         if (!$overview) {
                             $err = true;
                             break;
@@ -1291,7 +1248,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                     }
                 } else {
                     if (is_null($overview)) {
-                        $overview = imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
+                        $overview = @imap_fetch_overview($this->_stream, $seq, empty($options['sequence']) ? FT_UID : 0);
                         if (!$overview) {
                             $err = true;
                             break;
@@ -1303,7 +1260,6 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
                 }
             }
         }
-        error_reporting($old_error);
 
         if ($err) {
             $this->_exception('Error when fetching messages: ' . imap_last_error());
@@ -1411,18 +1367,14 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
             ? '1:*'
             : $this->utils->toSequenceString($options['ids']);
 
-        $old_error = error_reporting(0);
-
         if (!empty($options['add'])) {
-            $res = imap_setflag_full($this->_stream, $seq, implode(' ', $options['add']), empty($options['sequence']) ? ST_UID : 0);
+            $res = @imap_setflag_full($this->_stream, $seq, implode(' ', $options['add']), empty($options['sequence']) ? ST_UID : 0);
         }
 
         if (($res === true) && !empty($options['remove'])) {
-            $res = imap_clearflag_full($this->_stream, $seq, implode(' ', $options['remove']), empty($options['sequence']) ? ST_UID : 0);
+            $res = @imap_clearflag_full($this->_stream, $seq, implode(' ', $options['remove']), empty($options['sequence']) ? ST_UID : 0);
         }
 
-        error_reporting($old_error);
-
         if ($res === false) {
             $this->_exception('Error when flagging messages: ' . imap_last_error());
         }
@@ -1461,9 +1413,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
             ? '1:*'
             : $this->utils->toSequenceString($options['ids']);
 
-        $old_error = error_reporting(0);
-        $res = imap_mail_copy($this->_stream, $seq, $this->_connString($dest), $opts);
-        error_reporting($old_error);
+        $res = @imap_mail_copy($this->_stream, $seq, $this->_connString($dest), $opts);
 
         if ($res === false) {
             if (!empty($options['create'])) {
@@ -1495,9 +1445,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
 
         $this->login();
 
-        $old_error = error_reporting(0);
-        $res = imap_set_quota($this->_stream, $root, $options['storage']);
-        error_reporting($old_error);
+        $res = @imap_set_quota($this->_stream, $root, $options['storage']);
 
         if ($res === false) {
             $this->_exception('Error when setting quota: ' . imap_last_error());
@@ -1518,11 +1466,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         $this->login();
 
-        $old_error = error_reporting(0);
-        $res = imap_get_quota($this->_stream, $root);
-        error_reporting($old_error);
-
-        if ($res === false) {
+        if (@imap_get_quota($this->_stream, $root) === false) {
             $this->_exception('Error when retrieving quota: ' . imap_last_error());
         }
     }
@@ -1542,15 +1486,13 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
     {
         $this->login();
 
-        $old_error = error_reporting(0);
         $res = imap_get_quotaroot($this->_stream, $mailbox);
-        error_reporting($old_error);
 
         if ($res === false) {
             $this->_exception('Error when retrieving quotaroot: ' . imap_last_error());
         }
 
-        return array($mailbox => $ret);
+        return array($mailbox => $res);
     }
 
     /**
@@ -1579,9 +1521,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
             return;
         }
 
-        $old_error = error_reporting(0);
-        $res = imap_setacl($this->_stream, $mailbox, $identifier, (empty($options['remove']) ? '+' : '-') . $implode('', $options['rights']));
-        error_reporting($old_error);
+        $res = @imap_setacl($this->_stream, $mailbox, $identifier, (empty($options['remove']) ? '+' : '-') . $implode('', $options['rights']));
 
         if ($res === false) {
             $this->_exception('Error when setting ACL: ' . imap_last_error());
@@ -1602,10 +1542,7 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         $this->login();
 
         $acl = array();
-
-        $old_error = error_reporting(0);
-        $res = imap_getacl($this->_stream, $mailbox);
-        error_reporting($old_error);
+        $res = @imap_getacl($this->_stream, $mailbox);
 
         if ($res === false) {
             $this->_exception('Error when retrieving ACLs: ' . imap_last_error());
index a24ce3c..8241216 100644 (file)
@@ -275,9 +275,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             // STARTTLS returns no untagged response.
             $this->_sendLine('STARTTLS');
 
-            $old_error = error_reporting(0);
-            $res = stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
-            error_reporting($old_error);
+            $res = @stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
 
             if (!$res) {
                 $this->logout();
@@ -426,9 +424,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             break;
         }
 
-        $old_error = error_reporting(0);
-        $this->_stream = stream_socket_client($conn . $this->_params['hostspec'] . ':' . $this->_params['port'], $error_number, $error_string, $this->_params['timeout']);
-        error_reporting($old_error);
+        $this->_stream = @stream_socket_client($conn . $this->_params['hostspec'] . ':' . $this->_params['port'], $error_number, $error_string, $this->_params['timeout']);
 
         if ($this->_stream === false) {
             $this->_stream = null;
index 92abb81..0e05099 100644 (file)
@@ -204,9 +204,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
 
             $this->_sendLine('STLS');
 
-            $old_error = error_reporting(0);
-            $res = stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
-            error_reporting($old_error);
+            $res = @stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
 
             if (!$res) {
                 $this->logout();
@@ -276,9 +274,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             break;
         }
 
-        $old_error = error_reporting(0);
-        $this->_stream = stream_socket_client($conn . $this->_params['hostspec'] . ':' . $this->_params['port'], $error_number, $error_string, $this->_params['timeout']);
-        error_reporting($old_error);
+        $this->_stream = @stream_socket_client($conn . $this->_params['hostspec'] . ':' . $this->_params['port'], $error_number, $error_string, $this->_params['timeout']);
 
         if ($this->_stream === false) {
             $this->_stream = null;
index 902b7a9..b54f997 100644 (file)
@@ -76,10 +76,7 @@ class Horde_Imap_Client_Utf7imap
             self::$_mbstring = extension_loaded('mbstring');
         }
         if (self::$_mbstring) {
-            $old_error = error_reporting(0);
-            $output = mb_convert_encoding($str, 'UTF-8', 'UTF7-IMAP');
-            error_reporting($old_error);
-            return $output;
+            return @mb_convert_encoding($str, 'UTF-8', 'UTF7-IMAP');
         }
 
         $str = strval($str);
@@ -177,10 +174,7 @@ class Horde_Imap_Client_Utf7imap
             self::$_mbstring = extension_loaded('mbstring');
         }
         if (self::$_mbstring) {
-            $old_error = error_reporting(0);
-            $output = mb_convert_encoding($str, 'UTF7-IMAP', 'UTF-8');
-            error_reporting($old_error);
-            return $output;
+            return @mb_convert_encoding($str, 'UTF7-IMAP', 'UTF-8');
         }
 
         $u8len = strlen($str);
index 93e9543..45a2449 100644 (file)
@@ -276,8 +276,6 @@ class Horde_Memcache implements Serializable
             }
         }
 
-        $old_error = error_reporting(0);
-
         foreach ($keys as $k) {
             $out_array[$k] = false;
             if (isset($res[$key_map[$k]])) {
@@ -292,14 +290,12 @@ class Horde_Memcache implements Serializable
                         }
                     }
                 }
-                $out_array[$k] = unserialize($data);
+                $out_array[$k] = @unserialize($data);
             } elseif (isset($os[$k]) && !isset($res[$key_map[$k]])) {
                 $this->delete($k);
             }
         }
 
-        error_reporting($old_error);
-
         return ($ret_array) ? $out_array : reset($out_array);
     }
 
@@ -316,11 +312,7 @@ class Horde_Memcache implements Serializable
      */
     public function set($key, $var, $expire = 0)
     {
-        $old_error = error_reporting(0);
-        $var = serialize($var);
-        error_reporting($old_error);
-
-        return $this->_set($key, $var, $expire);
+        return $this->_set($key, @serialize($var), $expire);
     }
 
     /**
@@ -379,9 +371,7 @@ class Horde_Memcache implements Serializable
      */
     public function replace($key, $var, $expire = 0)
     {
-        $old_error = error_reporting(0);
-        $var = serialize($var);
-        error_reporting($old_error);
+        $var = @serialize($var);
         $len = strlen($var);
 
         if ($len > self::MAX_SIZE) {
index 56e692e..8dd5c0f 100644 (file)
@@ -123,16 +123,14 @@ class Horde_Text_Filter_Text2html extends Horde_Text_Filter_Base
         }
 
         /* For level MICRO or NOHTML, start with htmlspecialchars(). */
-        $old_error = error_reporting(0);
-        $text2 = htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
+        $text2 = @htmlspecialchars($text, ENT_COMPAT, $this->_params['charset']);
 
         /* Bad charset input in may result in an empty string. If so, try
          * using the default charset encoding instead. */
         if (!$text2) {
-            $text2 = htmlspecialchars($text, ENT_COMPAT);
+            $text2 = @htmlspecialchars($text, ENT_COMPAT);
         }
         $text = $text2;
-        error_reporting($old_error);
 
         /* Do in-lining of http://xxx.xxx to link, xxx@xxx.xxx to email. */
         if ($this->_params['parselevel'] < self::NOHTML) {
index fe8a2ec..4c94945 100644 (file)
@@ -158,9 +158,7 @@ class Horde_String
 
         /* Try mbstring. */
         if (Horde_Util::extensionExists('mbstring')) {
-            $old_error = error_reporting(0);
-            $out = mb_convert_encoding($input, $to, self::_mbstringCharset($from));
-            error_reporting($old_error);
+            $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from));
             if (!empty($out)) {
                 return $out;
             }
@@ -188,9 +186,7 @@ class Horde_String
                 if (is_null($charset)) {
                     throw new InvalidArgumentException('$charset argument must not be null');
                 }
-                $old_error = error_reporting(0);
-                $ret = mb_strtolower($string, self::_mbstringCharset($charset));
-                error_reporting($old_error);
+                $ret = @mb_strtolower($string, self::_mbstringCharset($charset));
                 if (!empty($ret)) {
                     return $ret;
                 }
@@ -226,9 +222,7 @@ class Horde_String
                 if (is_null($charset)) {
                     throw new InvalidArgumentException('$charset argument must not be null');
                 }
-                $old_error = error_reporting(0);
-                $ret = mb_strtoupper($string, self::_mbstringCharset($charset));
-                error_reporting($old_error);
+                $ret = @mb_strtoupper($string, self::_mbstringCharset($charset));
                 if (!empty($ret)) {
                     return $ret;
                 }
@@ -299,9 +293,7 @@ class Horde_String
 
         /* Try iconv. */
         if (Horde_Util::extensionExists('iconv')) {
-            $old_error = error_reporting(0);
-            $ret = iconv_substr($string, $start, $length, $charset);
-            error_reporting($old_error);
+            $ret = @iconv_substr($string, $start, $length, $charset);
 
             /* iconv_substr() returns false on failure. */
             if ($ret !== false) {
@@ -311,9 +303,7 @@ class Horde_String
 
         /* Try mbstring. */
         if (Horde_Util::extensionExists('mbstring')) {
-            $old_error = error_reporting(0);
-            $ret = mb_substr($string, $start, $length, self::_mbstringCharset($charset));
-            error_reporting($old_error);
+            $ret = @mb_substr($string, $start, $length, self::_mbstringCharset($charset));
 
             /* mb_substr() returns empty string on failure. */
             if (strlen($ret)) {
@@ -342,9 +332,7 @@ class Horde_String
         }
 
         if (Horde_Util::extensionExists('mbstring')) {
-            $old_error = error_reporting(0);
-            $ret = mb_strlen($string, self::_mbstringCharset($charset));
-            error_reporting($old_error);
+            $ret = @mb_strlen($string, self::_mbstringCharset($charset));
             if (!empty($ret)) {
                 return $ret;
             }
@@ -370,9 +358,7 @@ class Horde_String
     {
         if (Horde_Util::extensionExists('mbstring')) {
             $track_errors = ini_set('track_errors', 1);
-            $old_error = error_reporting(0);
-            $ret = mb_strpos($haystack, $needle, $offset, self::_mbstringCharset($charset));
-            error_reporting($old_error);
+            $ret = @mb_strpos($haystack, $needle, $offset, self::_mbstringCharset($charset));
             ini_set('track_errors', $track_errors);
             if (!isset($php_errormsg)) {
                 return $ret;
@@ -592,18 +578,15 @@ class Horde_String
 
         $charset = self::_mbstringCharset($charset);
         $old_charset = mb_regex_encoding();
-        $old_error = error_reporting(0);
 
         if ($charset != $old_charset) {
-            mb_regex_encoding($charset);
+            @mb_regex_encoding($charset);
         }
-        $alpha = !mb_ereg_match('[^[:alpha:]]', $string);
+        $alpha = !@mb_ereg_match('[^[:alpha:]]', $string);
         if ($charset != $old_charset) {
-            mb_regex_encoding($old_charset);
+            @mb_regex_encoding($old_charset);
         }
 
-        error_reporting($old_error);
-
         return $alpha;
     }
 
index 05f2efd..d7df361 100644 (file)
@@ -269,9 +269,7 @@ class Horde_Xml_Element implements ArrayAccess
         if (is_string($this->_element)) {
             $doc = new DOMDocument;
             $doc->preserveWhiteSpace = false;
-            $e = error_reporting(0);
-            $loaded = $doc->loadXML($this->_element);
-            error_reporting($e);
+            $loaded = @$doc->loadXML($this->_element);
             if (!$loaded) {
                 throw new Horde_Xml_Element_Exception('DOMDocument cannot parse XML: ', error_get_last());
             }
index 163da59..1d042cd 100644 (file)
@@ -95,17 +95,10 @@ readability::
   $short         = foo($bar);
   $long_variable = foo($baz);
 
-The "@" operator can be used to silence any errors that a function
-call may generate. This should be used with caution, as it is both
-slow and prone to pitfalls. For example, if you use it to silence
-including a file that may not exist, the main goal - not throwing
-warnings if the file isn't there - will be accomplished. But if the
-file does exist but has a parse error, the entire script or page will
-die with no warning. Because of problems like this, using "@" to
-silence function calls should be avoided whenever possible.
-
-In place of "@", using error_reporting() appropriately around
-code blocks that should not emit warnings is actually faster.
+The "@" operator can be used to silence any errors that a function call may
+generate. This should be used with caution, as any fatal errors will be
+completely transparent to the user. Only use "@" to silence functions that,
+e.g., emit warnings when the data input is incorrect (such as unserialize()).
 
 
 Function Definitions
index 06059c6..19032d1 100644 (file)
@@ -49,7 +49,5 @@ $__autoloader->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/
  * output this unless an admin. */
 set_exception_handler(array('Horde', 'fatal'));
 
-/* Catch and log E_DEPRECATED errors. */
-if (defined('E_DEPRECATED')) {
-    set_error_handler(array('Horde', 'logDeprecated'), E_DEPRECATED);
-}
+/* Catch errors. */
+set_error_handler(array('Horde', 'errorHandler'), E_ALL);
index 27c7994..4299234 100644 (file)
@@ -250,13 +250,11 @@ class IMP_Hooks
 //        $ldapPort = '389';
 //        $searchBase = 'ispmanDomain=' . $vdomain  . ",o=ispman";
 //
-//        $old_error = error_reporting(0);
-//        $ds = ldap_connect($ldapServer, $ldapPort);
-//        $searchResult = ldap_search($ds, $searchBase, 'uid=' . $vdomain);
-//        $information = ldap_get_entries($ds, $searchResult);
+//        $ds = @ldap_connect($ldapServer, $ldapPort);
+//        $searchResult = @ldap_search($ds, $searchBase, 'uid=' . $vdomain);
+//        $information = @ldap_get_entries($ds, $searchResult);
 //        $trailer = $information[0]['ispmandomainsignature'][0];
-//        ldap_close($ds);
-//        error_reporting($old_error);
+//        @ldap_close($ds);
 //
 //        return $trailer;
 //    }
index bf1c207..7e9d2bf 100644 (file)
@@ -996,9 +996,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
 
         // Convert IDN hosts to ASCII.
         if (function_exists('idn_to_ascii')) {
-            $old_error = error_reporting(0);
-            $host = idn_to_ascii($host);
-            error_reporting($old_error);
+            $host = @idn_to_ascii($host);
         } elseif (Horde_Mime::is8bit($ob['mailbox'], 'UTF-8')) {
             throw new IMP_Compose_Exception(sprintf(_("Invalid character in e-mail address: %s."), $email));
         }
index 2d559e2..4d2ec80 100644 (file)
@@ -126,13 +126,11 @@ class IMP_Ui_Mailbox
         }
 
         if (!empty($ret['from']) && !empty($options['specialchars'])) {
-            $old_error = error_reporting(0);
-            $res = htmlspecialchars($ret['from'], ENT_QUOTES, $options['specialchars']);
+            $res = @htmlspecialchars($ret['from'], ENT_QUOTES, $options['specialchars']);
             if (empty($res)) {
-                $res = htmlspecialchars($ret['from']);
+                $res = @htmlspecialchars($ret['from']);
             }
             $ret['from'] = $res;
-            error_reporting($old_error);
         }
 
         return $ret;
index bb19b9a..2c52341 100644 (file)
@@ -2065,9 +2065,7 @@ abstract class Kronolith_Event
                     if (isset($url['host'])) {
                         // Convert IDN hosts to ASCII.
                         if (function_exists('idn_to_ascii')) {
-                            $old_error = error_reporting(0);
-                            $url['host'] = idn_to_ascii($url['host']);
-                            error_reporting($old_error);
+                            $url['host'] = @idn_to_ascii($url['host']);
                         } elseif (Horde_Mime::is8bit($url['host'])) {
                             //throw new Kronolith_Exception(_("Invalid character in URL."));
                             $url['host'] = '';