php.net |  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.
Password:
Status:
Package:
Bug Type:
Summary:
From: kazu9su at gmail dot com
New email:
PHP Version: OS:

 

 [2016-07-20 08:33 UTC] kazu9su at gmail dot com
Description:
------------
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:
---------------
<?php

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


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
bool(true)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-20 10:12 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-07-20 10:12 UTC] nikic@php.net
This has been fixed in PHP 7.0 as part of https://wiki.php.net/rfc/internal_constructor_behaviour.
 [2016-07-20 10:29 UTC] cmb@php.net
As Nikita said, that has been fixed, but it seems noteworthy that
no PDOException is thrown in this case, but rather TypeError, see
<https://3v4l.org/jfChu>.
 [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