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 631863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:00:49+00:00 2026-05-13T20:00:49+00:00

So I’ve run into a bit of an issue. I know of a solution

  • 0

So I’ve run into a bit of an issue. I know of a solution but it doesn’t seem very clean and I’m wondering if there’s a better one.

I’m writing a MySQLi wrapper for running prepared statements. As it’s a wrapper and is meant to be reused (dynamic) the amount of columns returned depends on the query and isn’t static.

The one solution to this that I’ve found, and seems is what everyone uses, is call_user_func_array.

It works, but my issue with it is it has me creating an extra array of references that I shouldn’t really need in the first place.

For example:

<?php

// Connect, prepare statement, etc.

$stmt->execute();

$fields = $stmt->result_metadata();
$fields = $fields->fetch_fields();

foreach ($fields as $field) {
    // Unnecessary creation of an array.
    $params[] = &$row[$field->name];
}

call_user_func_array(array($stmt, 'bind_result'), $params);

?>

So now I’m creating another array just to get call_user_func_array to pass the parameters by reference because it doesn’t adhere to the method definition.

Is there some way to get call_user_func_array to adhere to method / function definitions? Is there a cleaner way of calling a method / function with a variable number of parameters? Or, is there just an overall cleaner and better solution to this issue all together?

I’ve also run into similar problems when calling bind_param while trying to keep the feature of being able to change the bound parameters and rerunning the statement intact.

On somewhat of a side issue, what exactly is the code below doing.

$row[$field->name] = &$row[$field->name];

It oddly works and doesn’t produce any errors, though I don’t exactly get how a variable can reference itself. Are there any major differences between that and the former other than the fact I’m not creating another array? Is it better?

Thanks.

EDIT:

This is how I used the Reflection API instead of call_user_fun_array. Any input on my usage of it, performance vs. call_user_func_array, implementation, etc. would be greatly appreciated. I haven’t really messed with it before and just about every method is undocumented so I’m not really sure of the proper way to use them.

<?php

foreach ($fields as $field) {
    $row[$field->name] = NULL;
}

$refMethod = new ReflectionMethod($stmt, 'bind_result');
$refMethod->invokeArgs($stmt, $row);

?>
  • 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-13T20:00:49+00:00Added an answer on May 13, 2026 at 8:00 pm

    One way i know of is that you can use the Reflection class’s isPassedByReference method.

    Here is a solution i came up with after facing that issue for a framework i have had been developing.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
I need to clean up various Word 'smart' characters in user input, including but
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.