|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81040 Native pass-by-ref in mysqli_stmt::bind_param leaks reference
Submitted: 2021-05-13 16:30 UTC Modified: 2021-05-26 19:56 UTC
From: Assigned: cmb (profile)
Status: Not a bug Package: Unknown/Other Function
PHP Version: 8.0.6 OS: Windows 10
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.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2021-05-13 16:30 UTC]
Native pass-by-reference makes elements of an array referenced. Tested with mysqli_stmt::bind_param. This results in inadvertent changes to follow up code, e.g. results from array_diff()

I don't know if it's intended behaviour or if not then which component this is related to. Additionally, should the reference leak through array_diff()?

Test online:

Test script:

$mysqli = new mysqli('localhost', 'user', 'password', 'test');

function a(&$a, &$b, &$c)
    $a = 3;

$foo = [1, 2, 3];
$bar = [3, 4, 5];

$stmt = $mysqli->prepare("SELECT ?,?,?");

// What's the difference between this
$stmt->bind_param('sss', $foo[0], $foo[1], $foo[2]);
// and this
a($foo[0], $foo[1], $foo[2]);

$diff = array_diff($foo, $bar);
$foo[1] = 'hi';

Expected result:
array(1) {
  [1] =>

Actual result:
array(1) {
  [1] =>
  string(2) "hi"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-21 12:52 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-05-21 12:52 UTC]
This doesn't appear to be particularly related to PHP 8.0.

Anyway, what is the behavior with libmysql-client.  It seems to me
that would yield the expected behavior.
 [2021-05-21 13:31 UTC]
That "reference leak" is by design, to allow rebinding of the
parameters like demonstrated in the first example for

If MySQLi built against libmysql-client behaves differently, that
was a bug.

[1] <>
 [2021-05-26 19:56 UTC]
-Status: Feedback +Status: Not a bug
 [2021-05-26 19:56 UTC]
As explained by CMB this is not a bug, at least not when compiled with mysqlnd
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 08:01:31 2024 UTC