Do not convert incorrect code types to integer automatically.
authorGunnar Wrobel <p@rdus.de>
Thu, 11 Feb 2010 08:29:43 +0000 (09:29 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Thu, 11 Feb 2010 10:07:58 +0000 (11:07 +0100)
If $code is null it will be converted to 0 by the default Exception
anyhow.

If $code contains a string it will elicit a Fatal Error. But that is
okay and should not be hidden. In nearly all cases where we provided a
string as $code it was a simple coding error that needs to be fixed.

There may be cases where the code is a value returned from another
library. If it is uncertain that the library ensures that the return
value is an integer then it can be cast into an integer before
providing it to the exception.

framework/Exception/lib/Horde/Exception.php
framework/Exception/lib/Horde/Exception/LastError.php
framework/Exception/lib/Horde/Exception/NotFound.php
framework/Exception/lib/Horde/Exception/PermissionDenied.php

index 49f4a5c..f849a72 100644 (file)
@@ -17,7 +17,7 @@ class Horde_Exception extends Exception
      *
      * @param mixed $message The exception message, a PEAR_Error
      *                       object, or an Exception object.
-     * @param mixed $code    A numeric error code.
+     * @param int   $code    A numeric error code.
      */
     public function __construct($message = null, $code = null)
     {
@@ -30,12 +30,6 @@ class Horde_Exception extends Exception
             $message = $message->getMessage();
         }
 
-        if (is_null($code)) {
-            $code = 0;
-        } else if (is_string($code)) {
-            $code = null;
-        }
-
         parent::__construct($message, $code);
     }
 
index cb30d67..44c3a20 100644 (file)
@@ -23,7 +23,7 @@ class Horde_Exception_LastError extends Horde_Exception
      *
      * @param mixed $message             The exception message, a PEAR_Error
      *                                   object, or an Exception object.
-     * @param mixed  $code_or_lasterror  Either a numeric error code, or
+     * @param mixed $code_or_lasterror   Either a numeric error code, or
      *                                   an array from error_get_last().
      */
     public function __construct($message = null, $code_or_lasterror = null)
index 8deeabf..9b7dfa3 100644 (file)
@@ -19,7 +19,7 @@ class Horde_Exception_NotFound extends Horde_Exception
      *
      * @param mixed $message The exception message, a PEAR_Error
      *                       object, or an Exception object.
-     * @param mixed $code    A numeric error code.
+     * @param int   $code    A numeric error code.
      */
     public function __construct($message = null, $code = null)
     {
index 547f606..31a53fa 100644 (file)
@@ -19,7 +19,7 @@ class Horde_Exception_PermissionDenied extends Horde_Exception
      *
      * @param mixed $message The exception message, a PEAR_Error
      *                       object, or an Exception object.
-     * @param mixed $code    A numeric error code.
+     * @param int   $code    A numeric error code.
      */
     public function __construct($message = null, $code = null)
     {