How to change this PHP 5.3 code to PHP 5.4?

Asked

Viewed 389 times

2

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

I’m having the following mistake:

Strict Standards: Only variables should be passed by Ference in /home/public_html/admin/additor.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');
}
  • Are you sure that this is the same location where the error is displayed? Looking quickly didn’t notice anything.

  • Check that in the line above the error nothing is missing.

  • Yes error in renamed $filename = strtolower(end(explodes('. ', $filename original_changed)));

  • Edit the question and add the error message. The code does not seem to use any deprecated or discontinued function.

  • Ready is appearing the error that is in the edition in bold above. It is that Host restriction that I am hosting the site ?

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 intermediary variable that takes the array of explode(), then pass her on to end().

Stay tuned to look at the php manual most of the functions you have &(commercial) indicate that the parameter must be a variable and not a value or function return.

Mixed end ( array &$array )

The code should stay that way:

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

Complementing the gmsantos commentary, from php5.3 E_STRICT does not belong to E_ALL. Already in php5.4 E_STRICT became part of E_ALL. To display 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);
  • 2

    Thanks for the help now run legal ^_^

  • 2

    Great tip from &. I’d had this problem before, but I didn’t know what cases happened.

  • @Rodrigorigotti, there’s a smarter way to solve this problem, you don’t know him, you’re in that reply

  • Thanks there for your help also serious and fire these mistakes that gives except that if I leave in php 5.3 do not give it.

  • 1

    If the error does not appear in PHP 5.3 it is because of this type of errors (Strict Bugs is disabled).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.