Doc #65465 [Com]: passing ArrayAccess to PDO constructor
Edit report at https://bugs.php.net/bug.php?id=65465&edit=1
ID: 65465
Comment by: giw42161 at uooos dot com
Reported by: gongteng524702837 at gmail dot com
Summary: passing ArrayAccess to PDO constructor
Status: Not a bug
Type: Documentation Problem
Package: PDO related
Operating System: linux 64bit
PHP Version: 5.5.2
Block user comment: N
Private report: N
New Comment:
(https://centurylawfirm.in/)gist.github.com
Previous Comments:
------------------------------------------------------------------------
[2014-02-01 09:14:57] krakjoe@php.net
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.
------------------------------------------------------------------------
[2013-08-17 13:16:34] gongteng524702837 at gmail dot com
Description:
------------
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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65465&edit=1
Thread (4 messages)