Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1058509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:02:14+00:00 2026-05-16T18:02:14+00:00

Possible Duplicate: Is it possible to pass parameters by reference using call_user_func_array()? I have

  • 0

Possible Duplicate:
Is it possible to pass parameters by reference using call_user_func_array()?

I have the following line of code which worked in PHP 5.1, but isn’t working in PHP 5.3.

$input = array('ss','john','programmer');
call_user_func_array(array($mysqli_stmt, 'bind_param'), $input);

In PHP 5.3, I get the following warning message:

Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in /var/www/startmission/em/class/cls.data_access_object.php on line 785

I changed the code to the following and it worked:

$a = 'johnl';
$b = 'programmer';
$mysqli_stmt->bind_param('ss',$a,$b);

I found this in the php documentation:

Care must be taken when using mysqli_stmt_bind_param() in
conjunction with call_user_func_array(). Note that
mysqli_stmt_bind_param() requires parameters to be passed by reference,
whereas call_user_func_array() can accept as a parameter a list of
variables that can represent references or values.

So my question is, how do I replicate the functionality of the call_user_func_array + bind_params such that i can dynamically bind variables at run time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:02:15+00:00Added an answer on May 16, 2026 at 6:02 pm

    I found the answer to my problem in a user note by fabio at kidopi dot com dot br3 years ago on the PHP manual page of mysqli_stmt::bind_param() (slightly modified):

    I used to have problems with call_user_func_array and bind_param after migrating to php 5.3.

    The cause is that 5.3 requires array values as reference while 5.2 worked with real values (but also with references). So I created a secondary helper function to help me with this:

    function refValues($arr)
    { 
            $refs = array();
    
            foreach ($arr as $key => $value)
            {
                $refs[$key] = &$arr[$key]; 
            }
    
            return $refs; 
    }
    

    and changed my previous function from:

    call_user_func_array(array($this->stmt, "bind_param"), $this->values); 
    

    to:

    call_user_func_array(array($this->stmt, "bind_param"), refValues($this->values)); 
    

    This way my db functions keep working in PHP 5.2/5.3 servers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Are there gotchas using varargs with reference parameters Hi, I have a
Possible Duplicate: Is Java pass by reference? In java are the parameters passed by
Possible Duplicate: PHP function with unlimited number of parameters How to pass array as
Possible Duplicate: How to pass an array via $_GET in php? So I have
Possible Duplicate: Is Java pass by reference? I have a question about passing by
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,
Possible Duplicate: pass data from Action To Another Action I have a view in
Possible Duplicate: pass by reference not working I was going through some of the
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: 'pass parameter by reference' in Ruby? in this example: def test verb

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.