Doc #65465 [Opn->Nab]: passing ArrayAccess to PDO constructor
| From: | krakjoe@php.net | Date: | Sat, 01 Feb 2014 09:14:57 +0000 |
| Subject: | Doc #65465 [Opn->Nab]: passing ArrayAccess to PDO constructor | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-10915@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65465&edit=1
ID: 65465
Updated by: krakjoe@php.net
Reported by: gongteng524702837 at gmail dot com
Summary: passing ArrayAccess to PDO constructor
-Status: Open
+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:
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.
Previous Comments:
------------------------------------------------------------------------
[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