php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76693 Notation / warning should be made for mutation of &$variable in bindParam.
Submitted: 2018-08-02 04:33 UTC Modified: 2020-04-07 12:38 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Dygear at gmail dot com Assigned: cmb (profile)
Status: Closed Package: PDO related
PHP Version: Irrelevant OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 + 32 = ?
Subscribe to this entry?

 
 [2018-08-02 04:33 UTC] Dygear at gmail dot com
Description:
------------
PDOStatement::bindParam mutates it's $variable type to string. This information, white donated in it's declaration (the ampersand), it doesn't mention the side effect that it will actually mutate that variable by converting it to a string.

Please make a notation that the $variable arg will be mutated to a string if it's not already. You should also note that if they wish to avoid this behavior they should use PDOStatement::execute and pass an array to it, as shown below.

Test script:
---------------
    public function getCalls(?DateTime $timeStart = null, ?DateTime $timeEnd = null): float
    {
        $statement = $this->db->prepare(self::SQL_GET_CALLS);
        $statement->bindParam(':timeStart', $timeStart);
        $statement->bindParam(':timeEnd', $timeEnd);
        $statement->execute();
        return (($statement->fetch()['Calls']) ?: 0.0) * 2;
    }

    public function getCalls(?DateTime $timeStart = null, ?DateTime $timeEnd = null): float
    {
        $statement = $this->db->prepare(self::SQL_GET_CALLS);
        $statement->execute([':timeStart' => $timeStart, ':timeEnd' => $timeEnd]);
        return (($statement->fetch()['Calls']) ?: 0.0) * 2;
    }


Expected result:
----------------
For the bindParam to NOT silently change the type of a variable I send it.

Actual result:
--------------
It changes the type of the variable I send it to a string ... How rude.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-02 10:34 UTC] cmb@php.net
-Package: Documentation problem +Package: PDO related
 [2020-04-07 12:38 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=349636
Log: Fix #76693: Notation / warning should be made for mutation of &$variable in bindParam
 [2020-04-07 12:38 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-04-07 12:38 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-04-07 12:40 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=badeacf359407e5f8e04e874b034405aaf18f089
Log: Fix #76693: Notation / warning should be made for mutation of &$variable in bindParam
 [2020-04-07 17:03 UTC] mumumu@php.net
Automatic comment from SVN on behalf of mumumu
Revision: http://svn.php.net/viewvc/?view=revision&revision=349641
Log: Fix #76693: Notation / warning should be made for mutation of &$variable in bindParam
 [2020-04-07 17:05 UTC] phpdocbot@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=8706904300688395936d660ff1c0918a4bb6c8a9
Log: Fix #76693: Notation / warning should be made for mutation of &$variable in bindParam
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Sep 29 01:01:25 2020 UTC