PHP: call_user_func_array: pass by reference issue

Sarfraz picture Sarfraz · Dec 15, 2009 · Viewed 8.2k times · Source

The below function generates error when a function contains referenced arguments eg:

function test(&$arg, &$arg2)
{
  // some code
}

Now I can not use call_user_func_array for above function, it will generate an error.

How to solve this problem?

I do need to use call_user_func_array.

Also assume that i don't know beforehand whether they are passed by reference or passed by value.

Thanks

Answer

Myles picture Myles · Dec 15, 2009

When storing your parameters in the array, make sure you are storing a reference to those parameters, it should work fine.

Ie:

call_user_func_array("test", array(&param1, &param2));