Bug #80637 [Opn]: bindParam() changes type property to string

From: Date: Tue, 26 Jan 2021 12:17:13 +0000
Subject: Bug #80637 [Opn]: bindParam() changes type property to string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231783@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80637&edit=1 ID: 80637 Updated by: cmb@php.net Reported by: php at evilazrael dot de Summary: bindParam() changes type property to string Status: Open Type: Bug Package: PDO Core Operating System: Linux PHP Version: 7.4.14 Block user comment: N Private report: N New Comment: @nikic: oops! Previous Comments: ------------------------------------------------------------------------ [2021-01-19 13:22:19] nikic@php.net @cmb: You didn't use the right property there: https://3v4l.org/tXjhi ------------------------------------------------------------------------ [2021-01-19 12:44:06] cmb@php.net There appears to be a more general issue: <https://3v4l.org/F6pnT>. ------------------------------------------------------------------------ [2021-01-17 19:45:52] 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80637&edit=1

« previous php.bugs (#231783) next »