From:             
Operating system: Ubuntu 9.10
PHP version:      5.3.2
Package:          PDO related
Bug Type:         Bug
Bug description:PDO constructor returns null instead of throwing an exception

Description:
------------
Calling 'new PDO(...)' returns null instead of raising an exception.



This behaviour was found, while trying to create a PDO object using an
sqlite database.



The database was created using the command 'sqlite3' from the console.
Attempting to open it from PHP using an 'sqlite2' dsn did not raised any
exception, but returned null from the object constructor.



I do not know if this happens with other PDO drivers, but in any case
constructors SHOULD throw an Exception on error, and not NULL.



A similar bug has been reported (http://bugs.php.net/bug.php?id=49320) but
since there is at least another case (http://bugs.php.net/bug.php?id=52042)
in which a constructor returns NULL when it should be throwing an
Exception, I decided to report this anyway.



I'm not sure if this goes beyond PDO, and it's a PHP feature that I've
never experienced before, but this type of code makes no sense at all,



$o = new SomeObject();

if($o === null) {

  // handle error ...

} else {

  $o->doSomething();

}



This is what is expected from OOP:



try {

   $o = new SomeObject();

   $o->doSomething();

} catch(Exception $x) {

   // handle error ...

}



Test script:
---------------
>From the console:



$ sqlite3 sqlite.db

sqlite> CREATE TABLE T(K VARCHAR(32));

sqlite> .q



>From a PHP script:



$pdo = new PDO('sqlite2:sqlite.db');

echo 'PDO is ', gettype($pdo), PHP_EOL;

Expected result:
----------------
PDO is object

Actual result:
--------------
PDO is NULL

-- 
Edit bug report at http://bugs.php.net/bug.php?id=52053&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52053&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52053&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52053&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52053&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52053&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52053&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52053&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52053&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52053&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52053&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52053&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52053&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52053&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52053&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52053&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52053&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52053&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52053&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52053&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52053&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52053&r=mysqlcfg

Reply via email to