Strict Standards: Only variables should be passed by reference - php error

user1578012 picture user1578012 · Aug 6, 2012 · Viewed 9.2k times · Source
    $file_name = $_FILES['profile_image']['name'];
    $file_ext = end(explode('.', $file_name)); //line 10
    $file_ext = strtolower($file_ext);
    $file_temp = $_FILES['profile_image']['tmp_name'];

Strict Standards: Only variables should be passed by reference in on line 10

How do I get rid of this error? Please and thank you :)

Answer

nickb picture nickb · Aug 6, 2012

end() expects its parameter to be able to be passed by reference, and only variables can be passed by reference:

$array = explode('.', $file_name);
$file_ext = end( $array); 

You can fix this by saving the array to a variable first, then calling end().