5

I got an error: Strict Standards: Only variables should be passed by reference

 $string =  array_shift(array_keys($_REQUEST));

How can I correct that ?

yarek
  • 10,010
  • 26
  • 106
  • 195

3 Answers3

18
$tmpArray = array_keys($_REQUEST);
$string =  array_shift($tmpArray);

Temporary array needed :(

Med
  • 1,985
  • 18
  • 29
2

Assign the result of array_keys($_REQUEST) to a variable and pass that variable to array_shift:

$var = array_keys($_REQUEST);
$string =  array_shift($var);
Maraboc
  • 10,125
  • 3
  • 34
  • 46
2

You might have a set up PHP to run under strict mode or it might have been the default behaviour.

Since output of array_keys($_REQUEST) is not a variable and under strict mode this will generate a warning. This behavior is extremely non-intuitive as the array_keys($_REQUEST) method returns an array value.

So to resolve this problem, assign the output of array_keys($_REQUEST) to a variable and then use it like below:

$keys = array_keys($_REQUEST);
$shift = array_shift($keys);
chandresh_cool
  • 11,600
  • 3
  • 27
  • 44