|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesbindparam-typed-props (last revision 2021-06-08 13:23 UTC by cmb@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-01-19 12:44 UTC] cmb@php.net
[2021-01-19 13:22 UTC] nikic@php.net
[2021-01-26 12:17 UTC] cmb@php.net
[2021-06-08 13:23 UTC] cmb@php.net
[2021-06-08 13:23 UTC] cmb@php.net
-Status: Open
+Status: Verified
-Operating System: Linux
+Operating System: *
[2021-06-08 13:23 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 00:00:02 2025 UTC |
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.