Doc #76693 [Opn->Csd]: Notation / warning should be made for mutation of &$variable in bindParam.

From: Date: Tue, 07 Apr 2020 12:38:40 +0000
Subject: Doc #76693 [Opn->Csd]: Notation / warning should be made for mutation of &$variable in bindParam.
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17467@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76693&edit=1 ID: 76693 Updated by: cmb@php.net Reported by: Dygear at gmail dot com Summary: Notation / warning should be made for mutation of &$variable in bindParam. -Status: Open +Status: Closed Type: Documentation Problem Package: PDO related Operating System: ALL PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2020-04-07 12:38:15] 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 ------------------------------------------------------------------------ [2018-08-02 04:33:26] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76693&edit=1

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