Bug #77954 [Fbk->Opn]: Binding value as PDO::PARAM_INT has different behaviour in PHP 7.2
| From: | f dot bosch at genkgo dot nl | Date: | Wed, 01 May 2019 09:10:21 +0000 |
| Subject: | Bug #77954 [Fbk->Opn]: Binding value as PDO::PARAM_INT has different behaviour in PHP 7.2 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220663@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77954&edit=1
ID: 77954
User updated by: f dot bosch at genkgo dot nl
Reported by: f dot bosch at genkgo dot nl
Summary: Binding value as PDO::PARAM_INT has different
behaviour in PHP 7.2
-Status: Feedback
+Status: Open
Type: Bug
Package: PDO MySQL
Operating System: Ubuntu
PHP Version: 7.2.17
Block user comment: N
Private report: N
New Comment:
You are right. I totally agree that the previous behaviour was not correct. Since I could not find
any reason why the behaviour change was there, no backward-incompatibility notice in this regard, I
was wondering if this is intensional. This could affect quite some people, especially those using
the Laravel framework and/or only its database component.
If you no idea, please just close the report.
Previous Comments:
------------------------------------------------------------------------
[2019-05-01 09:02:49] nikic@php.net
Why do you think the previous behavior was correct? It seems right to me that if an integer binding
is requested it should be bound as an integer.
------------------------------------------------------------------------
[2019-05-01 08:59:43] f dot bosch at genkgo dot nl
Description:
------------
When binding a value against a MySQL PDO statement, the behaviour between PHP 7.1 and PHP 7.2
differs. When you bind a value as integer while passing a float, this was no problem with PHP7.1.
However, it became a problem in PHP7.2.
The problem is when executing the following. It inserts 0.5 in PHP7.1, and 0 in PHP7.2. I have
tested this against MariaDB (10.1 and 10.2), not against MySQL. Another person also found difference
in behaviour: https://stackoverflow.com/questions/54413798/pdoparam-int-behaviour-in-php-7-1-php-7-2.
$stmt = $pdo->prepare('INSERT INTO tbl (val) VALUES (?)');
$stmt->bindValue(1, 0.5, PDO::PARAM_INT);
See also this pull request in the Laravel Framework for this behaviour change: https://github.com/laravel/framework/pull/28379.
Test script:
---------------
<?php
$pdo = new PDO('mysql:dbname=floattest;host=127.0.0.1', 'root', '');
$create = $pdo->prepare('CREATE TABLE IF NOT EXISTS tbl (val DECIMAL(9,2))');
$create->execute();
$del = $pdo->prepare('DELETE FROM tbl');
$del->execute();
$ins = $pdo->prepare('INSERT INTO tbl (val) VALUES (?)');
$ins->bindValue(1, 0.5, PDO::PARAM_INT);
$ins->execute();
$sel = $pdo->prepare('SELECT * FROM tbl');
$sel->execute();
var_dump($sel->fetchColumn(0));
Expected result:
----------------
0.5
Actual result:
--------------
0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77954&edit=1