Doc #76693 [NEW]: Notation / warning should be made for mutation of &$variable in bindParam.
| From: | Dygear at gmail dot com | Date: | Thu, 02 Aug 2018 04:33:26 +0000 |
| Subject: | Doc #76693 [NEW]: Notation / warning should be made for mutation of &$variable in bindParam. | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-15942@lists.php.net to get a copy of this message | ||
From: Dygear at gmail dot com
Operating system: ALL
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Notation / warning should be made for mutation of &$variable in bindParam.
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 bug report at https://bugs.php.net/bug.php?id=76693&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76693&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76693&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76693&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76693&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76693&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76693&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76693&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76693&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76693&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76693&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76693&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76693&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76693&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76693&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76693&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76693&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76693&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76693&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76693&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76693&r=mysqlcfg