php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49946 mysqli_stmt_bind_param saying parameter 3 is value not a reference
Submitted: 2009-10-21 15:20 UTC Modified: 2009-10-21 15:53 UTC
From: chris at network-13 dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.3.0 OS: Windows 7
Private report: No CVE-ID: None
 [2009-10-21 15:20 UTC] chris at network-13 dot com
Description:
------------
I tested this on both linux/windows with PHP 5.2.10 and it gave no problems. After updating the windows machine to PHP 5.3.0 it now gives the error.

Warning: Parameter 3 to mysqli_stmt_bind_param() expected to be a reference, value given

Reproduce code:
---------------
<?php
class db {
    public $result;    
    function getresult(){
        $connection = mysqli_connect('localhost', 'root', 'password', 'testdb');        
        $args = func_get_args();
        $query = array_shift($args);
         
        if(!$connection){ mysqli_connect_error(); exit(); }
        $sql = mysqli_prepare($connection, $query);
    
        $types = str_repeat('s', count($args));
        array_unshift($args, $types);
        array_unshift($args, $sql);
     
        call_user_func_array('mysqli_stmt_bind_param', $args); 
        mysqli_stmt_execute($sql);
        mysqli_stmt_bind_result($sql, $result);    
        mysqli_stmt_fetch($sql);
    
        mysqli_close($connection);
        $this->result = $result;        
    }
}

$uid = NEW db();
$uid->getresult("SELECT uid FROM testtable WHERE user = ?","Chris");
echo $uid->result;
?>

Expected result:
----------------
It should echo the uid of the user.

Actual result:
--------------
Warning: Parameter 3 to mysqli_stmt_bind_param() expected to be a reference, value given in D:\www\mysqli2.php on line 16

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-21 15:27 UTC] uw@php.net
Sounds like Bogus

http://de3.php.net/manual/en/function.call-user-func-array.php
-> Note: Referenced variables in param_arr  are passed to the function by a reference, others are passed by a value. In other words, it does not depend on the function signature whether the parameter is passed by a value or by a reference. 

call_user_func_array does call by value and mysqli_stmt_bind_param() is documented to expect variables passed by reference.

http://de3.php.net/manual/en/mysqli-stmt.bind-param.php
bool mysqli_stmt::bind_param  ( string $types  , mixed &$var1  [, mixed &$...  ] )


 [2009-10-21 15:38 UTC] chris at network-13 dot com
Does this mean 5.3.0 is correct in giving the error and 5.2.10 was wrong in letting it work?
 [2009-10-21 15:45 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

For supporting OUT-params this must be a reference. The value you're passing in can'T be referenced so PHP complains.

Older versions of PHP treated this situation wrong without complaining which was changed in order to help producing bug free code. Please see the user notes in the  call_user_func_array() man page for different work-arounds.
 [2009-10-21 15:53 UTC] uw@php.net
Thanks Johannes, I wasn't 100% sure about it... I asked Tony to add a note to the docs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 13:01:29 2024 UTC