|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65465 passing ArrayAccess to PDO constructor
Submitted: 2013-08-17 13:16 UTC Modified: 2014-02-01 09:14 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: gongteng524702837 at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.5.2 OS: linux 64bit
Private report: No CVE-ID: None
 [2013-08-17 13:16 UTC] gongteng524702837 at gmail dot com
Passing object that implement ArrayAccess interface to PDO constructor(forth 
param), the constructor will return NULL, no Exception raised.
(I‘m not sure is the bug come from PDO or ArrayAccess.)

Test script:
$config = array(...);

$options = new SomeObjImplArrAcc(); // just an empty object
$pdo = new PDO($config['dsn'],$config['user'],$config['pass'],$options);
var_dump($pdo); // <- NULL

$options[PDO::ATTR_PERSISTENT] = true; // or have some elements
$pdo = new PDO($config['dsn'],$config['user'],$config['pass'],$options);
var_dump($pdo); // <- NULL

// but success if convert to "native" array
$pdo = new PDO($config['dsn'],$config['user'],$config['pass'],(array)$options);
var_dump($pdo); // <- {PDO}[0]

Expected result:
construct three same PDO object


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-01 09:14 UTC]
-Status: Open +Status: Not a bug
 [2014-02-01 09:14 UTC]
Arrays and objects are not interchangeable, if a function is prototyped to accept an array then you must pass it an array, not an object.

Not a bug.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 10:01:28 2024 UTC