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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC