Search code examples
phpvariablesstandardsstrict

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


    $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 :)


Solution

  • 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().