php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70787 mysqli_stmt::bind_param() needs the “ready” variables only
Submitted: 2015-10-25 20:48 UTC Modified: 2021-09-28 16:18 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: it_poz at interia dot eu Assigned: cmb (profile)
Status: Closed Package: MySQLi related
PHP Version: Irrelevant OS: irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: it_poz at interia dot eu
New email:
PHP Version: OS:

 

 [2015-10-25 20:48 UTC] it_poz at interia dot eu
Description:
------------
The mysqli_stmt::bind_param() needs the “ready” variables but doesn’t accept the parameters as results – in such cases PHP parser outputs the Fatal error: Uncaught Error: “Cannot pass parameter 2 by reference”

Test script:
---------------
Example 1 (it works):

$stmt->bind_param('i', 1)

Example 2 (it doesn’t work and Fatal error is signaled):

$stmt->bind_param('i', ($i + 1))

Expected result:
----------------
I would expect this method working with the parameter’s values calculated in real time, not just only with “ready” values.

Actual result:
--------------
Uncaught Error: Cannot pass parameter 2 by reference - for the code example 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-28 16:18 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-09-28 16:18 UTC] cmb@php.net
As of PHP 8.1.0, you can pass an array of *values* to
mysqli_stmt::execute() instead of having to call
::bind_param()[1].  For previous PHP versions, you can use the
splat operator:

    $stmt->bind_param('i', ...[$i + 1])

[1] <https://www.php.net/manual/en/migration81.new-features.php#migration81.new-features.mysqli.bind-in-execute>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC