|  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: 2018-08-02 10:34 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Dygear at gmail dot com Assigned:
Status: Open Package: PDO related
PHP Version: Irrelevant OS: ALL
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-08-02 04:33 UTC] Dygear at gmail dot com
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);
        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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-02 10:34 UTC]
-Package: Documentation problem +Package: PDO related
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 20 17:01:24 2020 UTC