|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72628 PDO constructer return null when arguments are unexpected types
Submitted: 2016-07-20 08:33 UTC Modified: 2016-07-21 02:29 UTC
From: kazu9su at gmail dot com Assigned: nikic (profile)
Status: Closed Package: PDO related
PHP Version: 5.6.23 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: kazu9su at gmail dot com
New email:
PHP Version: OS:


 [2016-07-20 08:33 UTC] kazu9su at gmail dot com
PDO contructer return null and output warning() when given unexpected type arguments.
I think it is better that throw PDO exception with relevant message or update PHPDoc to indicate this specification.

How about that?

Test script:

try {
    $pdo = new PDO('pgsql:host=db;dbname=hoge', 'postgres', [], []);
} catch(PDOException $e) {

Expected result:
string(64) "PDO::__construct() expects parameter 3 to be string, array given"

Actual result:
Warning: PDO::__construct() expects parameter 3 to be string, array given in /Users/kazushige.tominaga/test-prestissimo/hoge.php on line 2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-20 10:12 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-07-20 10:12 UTC]
This has been fixed in PHP 7.0 as part of
 [2016-07-20 10:29 UTC]
As Nikita said, that has been fixed, but it seems noteworthy that
no PDOException is thrown in this case, but rather TypeError, see
 [2016-07-21 02:29 UTC] kazu9su at gmail dot com
I see. Thank you!
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 08 05:03:34 2021 UTC