How to change this PHP 5.3 code to PHP 5.4?

2

How can I change the code below to work in versions 5.3 and 5.4 of PHP? Currently works only in version 5.3.

I'm having the following error:

  

Strict Standards: Only variables should be passed by reference in   /home/public_html/admin/additional.php on line 1

$arquivo_renomeado = strtolower(end(explode('.', $nome_do_arquivo_original_alterado)));
if ($arquivo_renomeado == 'jpg' || $arquivo_renomeado == 'jpeg') {
    $nome_final = str_replace($nome_do_arquivo_original_alterado,' ',$nome_da_imagem_alterada.'.jpg');
} else if ($arquivo_renomeado == 'png') {
    $nome_final = str_replace($nome_do_arquivo_original_alterado,' ',$nome_da_imagem_alterada.'.png');
# Only if your version of GD includes GIF support
} else if ($arquivo_renomeado == 'gif') {
    $nome_final = str_replace($nome_do_arquivo_original_alterado,' ',$nome_da_imagem_alterada.'.gif');
}
    
asked by anonymous 05.01.2015 / 20:28

1 answer

4

The error says that you are required to pass a variable (reference) to end function, it is not possible to pass the return of a function / method. To fix create an intermediate variable that gets the array of explode () , then pass it to end () .

Keep in mind when looking at the php manual, most of the functions that have & (and commercial) indicate that the parameter must be a variable and not a value or function return.

  

mixed end (array & array)

The code should look like this:

$nome_do_arquivo_original_alterado = 'teste.png';
$arr = explode('.', $nome_do_arquivo_original_alterado);
$arquivo_renomeado = strtolower(end($arr));

Complementing the gmsantos comment, as of php5.3 E_STRICT does not belong to E_ALL . Already in php5.4 E_STRICT happened to be part of E_ALL . To display the errors / warnings E_STRICT in php5.3 add these two lines at the beginning of the script:

 ini_set('display_errors', true);
 error_reporting(E_ALL | E_STRICT);
    
05.01.2015 / 21:46