Doc #65465 [Com]: passing ArrayAccess to PDO constructor

From: Date: Mon, 04 Jul 2022 07:31:06 +0000
Subject: Doc #65465 [Com]: passing ArrayAccess to PDO constructor
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-19471@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
 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
(https://centurylawfirm.in/blog/divorce-lawyer-in-delhi-2/)gist.github.com
(https://centurylawfirm.in/blog/debt-recovery-tribunal-drt/)gist.github.com
(https://centurylawfirm.in/blog/get-bail-in-india/)gist.github.com
(https://centurylawfirm.in/blog/best-lawyer-for-criminal-case/)gist.github.com
(https://centurylawfirm.in/blog/high-court-cases/)gist.github.com
(https://centurylawfirm.in/blog/cheque-bounce-case/)gist.github.com
(https://centurylawfirm.in/blog/how-to-take-mutual-divorce/)gist.github.com


Previous Comments:
------------------------------------------------------------------------
[2022-03-26 05:05:37] giw42161 at uooos dot com

(https://centurylawfirm.in/)gist.github.com

------------------------------------------------------------------------
[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)

« previous php.doc.bugs (#19471) next »