From: marcos dot neves at gmail dot com
Operating system: ANY
PHP version: 5.2.0
PHP Bug Type: Scripting Engine problem
Bug description: Exception code can´t be string
Description:
------------
The follow code is ok, cause 123, even as a string, it can be convert to
number.
new Exception("Message", "123");
The follow is not ok.
new Exception("Message", "NotNumber");
PHP is not a typed language, why Exception must have a number as code?
The problem is that error code doesn´t means "Number error code" but could
be a string error code, like mysql 5.1 uses.
Check the follow reproduce able code.
Reproduce code:
---------------
<?
error_reporting(E_ALL);
$host = "localhost";
$dbName = "test";
$user = "root";
$passwd = "";
$mysqlDsn = "mysql:host=$host;$dbName";
$pdo = new PDO($mysqlDsn, $user, $passwd);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$pdo->query("SELECT version");
}catch(Exception $e){
$code = $e->getCode(); // 42S22
echo "<pre>";
var_dump($code); // string(5) "42S22"
throw new Exception($e->getMessage(), $code);
}
?>
Expected result:
----------------
The follow line, should accept the $code var, but doesn´t.
throw new Exception($e->getMessage(), $code);
It´s not consistent, since the Exception object constructor can´t accept a
non number as code, but it can return.
See:
$msg = $catchedPdoMysqlException->getMessage();
$code = $catchedPdoMysqlException->getCode();
new Exception($msg, $code); // $code is not valid one.
Actual result:
--------------
Exception code, should accept non numbers as a code value, as mysql does.
--
Edit bug report at http://bugs.php.net/?id=39615&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39615&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39615&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39615&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39615&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39615&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39615&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39615&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39615&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39615&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39615&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39615&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39615&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39615&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39615&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39615&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39615&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39615&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39615&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39615&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39615&r=mysqlcfg