|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-08-02 10:34 UTC] cmb@php.net
-Package: Documentation problem
+Package: PDO related
[2020-04-07 12:38 UTC] cmb@php.net
[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
[2020-04-07 12:40 UTC] phpdocbot@php.net
[2020-04-07 17:03 UTC] mumumu@php.net
[2020-04-07 17:05 UTC] phpdocbot@php.net
[2020-12-30 11:59 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
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.