Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array_pop() requires deprecated call-by-reference when invoked from call_user_func()

Tags:

php

php-5.3

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!

like image 667
Lennart Rolland Avatar asked Mar 09 '12 09:03

Lennart Rolland


1 Answers

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.

like image 85
BoltClock Avatar answered Sep 28 '22 03:09

BoltClock