-2

Recently I moved my website from localhost to a url domain, and now it keeps showing the errors above. The lines with problems are shown bellow. I think it's because the sintax that I used is from a more recent version of PHP, but I can't find any specific documentation for previous versions.

<?php echo explode(' ', $_SESSION['usuario_nome'])[0]; ?>

...

$fields_holder += [$name => $table_info[$i][$name]];

What is the equivalent of those lines of code to PHP < 5.4? Can anybody think of any other reason the code suddenly stopped working?

Sorry about my bad english...

Pedro H. Forli
  • 332
  • 2
  • 14
  • So you wrote code for PHP5.4 at test with a view to implement the code in PHP5.3. What can you say except Woops – RiggsFolly Feb 11 '16 at 22:58

2 Answers2

1

PHP5.3 does not support the short array syntax, it is new in PHP5.4

The syntax that should work in PHP < 5.4 and in PHP5.4 and > is

<?php 
    $t = explode(' ', $_SESSION['usuario_nome']); 
    echo $t[0];


    $fields_holder[] = array($name => $table_info[$i][$name]);

But I would guess that there is going to be more code that you are going to have to refactor if you have implemented this code on a server that is running PHP5.3

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

In previous version you have to use old double-line syntax:

$array = explode(' ', $_SESSION['usuario_nome']);
echo $array[0];

$array = array( $name => $table_info[$i][$name] );

The += syntax with array is unsupported even in PHP > 5.3

fusion3k
  • 11,568
  • 4
  • 25
  • 47