6
call_user_func('array_pop', $myarray);

gives 'Parameter 1 to array_pop() expected to be a reference, value given', while

call_user_func('array_pop', &$myarray);

gives 'Call-time pass-by-reference has been deprecated'.

So what am I supposed to do? I am on "PHP Version 5.3.5" on Windows, and turning of deprecated warnings isn't an option.

Thanks!

hakre
  • 193,403
  • 52
  • 435
  • 836
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • 1
    Maybe this serves as a workaround: http://stackoverflow.com/questions/295016/is-it-possible-to-pass-parameters-by-reference-using-call-user-func-array – Felix Kling Mar 09 '12 at 09:07

1 Answers1

5

Either just call it directly:

array_pop($myarray);

Or use call_user_func_array(), which accepts an array of references as parameters without yelling at you about call-time pass-by-reference:

call_user_func_array('array_pop', array(&$myarray));

The reason this doesn't raise a warning about call-time pass-by-reference is because nothing of that sort actually happens. There is a subtle difference between passing a variable by reference and creating an array of references and passing that array by value.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Thanks! I actually read that answer in some google result, but i failed to see that call_user_func was replaced with call_user_func_ARRAY and so i thought that i would have to change my function to nwrap the array (which wouln't be possible in my case, since i was using array_pop). – Mr. Developerdude Mar 09 '12 at 10:01