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
  • 11,278
  • 30
  • 120
  • 219

3 Answers3

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

Temporary array needed :(

Med
  • 2,035
  • 20
  • 31
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,550
  • 3
  • 37
  • 48
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,753
  • 3
  • 30
  • 45