Bug #72628 [Csd]: PDO constructer return null when arguments are unexpected types

From: Date: Thu, 21 Jul 2016 02:29:09 +0000
Subject: Bug #72628 [Csd]: PDO constructer return null when arguments are unexpected types
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202461@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72628&edit=1

 ID:                 72628
 User updated by:    kazu9su at gmail dot com
 Reported by:        kazu9su at gmail dot com
 Summary:            PDO constructer return null when arguments are
                     unexpected types
 Status:             Closed
 Type:               Bug
 Package:            PDO related
 PHP Version:        5.6.23
 Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

I see. Thank you!


Previous Comments:
------------------------------------------------------------------------
[2016-07-20 10:29:54] 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-20 10:12:26] 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 08:33:31] 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)


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72628&edit=1


Thread (4 messages)

« previous php.bugs (#202461) next »