php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80637 bindParam() changes type property to string
Submitted: 2021-01-17 19:45 UTC Modified: 2021-01-26 12:17 UTC
From: php at evilazrael dot de Assigned:
Status: Open Package: PDO Core
PHP Version: 7.4.14 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
29 + 29 = ?
Subscribe to this entry?

 
 [2021-01-17 19:45 UTC] php at evilazrael dot de
Description:
------------
Nothing new, but still unexpected. bindParam() changes the bound variable to type string. According to comments on bindParam() this is the normal behaviour for at least 11 years, but with the typed property support introduced in 7.4 this is even more unexpected to have an int property containing a string, something you can do directly.

I tested this with SQLite and PostgreSQL and seems to be independent of the used database. 


Test script:
---------------
<?php
class TestClass
{
    public int $a; 
}

$x = new TestClass; 
$x->a = 17; 
var_dump($x); 
/*
class TestClass#3 (1) {
  public int $a =>
  int(17)
}
*/

$db = new PDO("sqlite::memory:");
$stmt = $db->prepare("SELECT :val"); 
$stmt->bindValue(":val", $x->a); 
$stmt->execute(); 
$stmt->closeCursor(); 
var_dump($x); 
/*
class TestClass#3 (1) {
  public int $a =>
  int(17)
}
*/

$stmt->bindParam(":val", $x->a); 
$stmt->execute(); 
$stmt->closeCursor(); 
var_dump($x); 
/*
class TestClass#3 (1) {
  public int $a =>
  string(2) "17"
}
*/


Expected result:
----------------
Int typed property containing an int value

Actual result:
--------------
Int typed property containing a string. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-19 12:44 UTC] cmb@php.net
There appears to be a more general issue:
<https://3v4l.org/F6pnT>.
 [2021-01-19 13:22 UTC] nikic@php.net
@cmb: You didn't use the right property there: https://3v4l.org/tXjhi
 [2021-01-26 12:17 UTC] cmb@php.net
@nikic: oops!
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Apr 15 18:01:24 2021 UTC