500 Internal server error in PHP files

2

Every time I run a PHP file on the server it returns (at the header) a 500 error. This only happens with PHP files ...

Commands like echo and phpinfo() only with strings work (I tested with echo 'teste'; ). But if I go to use more complex codes, type include arrays and etc, it no longer works and that error.

I thought it might be a bug in my script, but it works at localhost ...

The output for ls -l in the public_html folder is as follows:

drwxr-xr-x 3 root root 4096 Jan 28 06:50 app
drwxr-xr-x 2 root root 4096 Jan 28 06:50 css
drwxr-xr-x 2 root root 4096 Jan 28 06:50 fonts
drwxr-xr-x 5 root root 4096 Jan 28 06:52 img
-rwxr-xr-x 1 root root  859 Jan 28 06:50 index.php
drwxr-xr-x 2 root root 4096 Jan 28 06:52 js

Thanks in advance.

@Edit:

Follow my complete script.

<?php

ini_set('display_errors', true);
error_reporting(E_ALL);

/*
 *  0 = confirmado
 *  1 = talvez
 *  2 = não vai
 */

$convidados = [
    'Cieli' => [0,15],
    'Carlinhos' => [0,30],
    'Daianna' => [1,0],
    'Renato' => [0,20],
    'Ana' => [3,0],
    'Larissa' => [0,20],
    'Debora' => [0,30],
    'Dani' => [0,0],
    'Suelen' => [1,0],
    'Vitor' => [1,0],
    'Felipe' => [1,0],
    'Luany' => [1,0],
    'Sandra' => [1,0],
    'Halysson' => [1,0],
    'Karina' => [3,0],
    'Mariana' => [3,0],
    'Wanessa' => [0,30],
    'Matheus' => [1,20],
    'Mauricio' => [3,0],
    'Mayara' => [1,20],
    'Lukas' => [1,0],
    'Leticia' => [1,0],
    'Geord' => [1,0],
    'Zé' => [3,0],
    'Luana' => [1,0],
    'Keity' => [0,20],
    'Werinton' => [0,20]
];

ksort($convidados);

$confirmed       = '<i class="fa fa-check"></i>';
$not_confirmed   = '<i class="fa fa-times"></i>';
$awaiting        = '<i class="fa fa-circle"></i>';
$total           = [];
$total_confirmed = 0;

foreach ($convidados as $key => $value) {
    $total[] = $convidados[$key][1];

    if( $convidados[$key][0] === 0 ) {
        $total_confirmed += 1;
    }
}

?>

<!DOCTYPE html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Site</title>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
        <link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/main.css">

        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
    </head>
    <body>

        <header>
            <h2>
                Site
            </h2>
        </header>

        <main role="main" class="main-width">
            <h3>Tabela de confirmados</h3>

            <table>
                <caption>
                    Legenda: (<?php echo $confirmed; ?>) Confirmado, (<?php echo $awaiting; ?>) Aguardando confirmação, (<?php echo $not_confirmed; ?>) Não confirmado
                </caption>
                <thead>
                    <tr>
                        <td>Convidado</td>
                        <td>Confirmado</td>
                        <td>Valor</td>
                    </tr>
                </thead>
                <tbody>
                <?php
                    foreach ($convidados as $key => $value) {
                        echo 
                            '
                            <tr>
                                <td>' . $key . '</td>
                                <td>' . ($convidados[$key][0] === 0 ? $confirmed : ($convidados[$key][0] === 1 ? $awaiting : $not_confirmed)) . '</td>
                                <td>R$' . number_format($convidados[$key][1], 2, ',', '.') . '</td>
                            </tr>
                            ';
                    }
                ?>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2">Total de confirmados: <?php echo $total_confirmed; ?></td>
                        <td colspan="1">Total arrecadado: R$<?php echo number_format(array_sum($total), 2, ',', '.'); ?></td>
                    </tr>
                </tfoot>
            </table>
        </main>

        <script src="js/main.js"></script>
    </body>
</html>
    
asked by anonymous 07.03.2015 / 00:04

1 answer

2

The shortened syntax for arrays is available from php5.4, like your production host uses a lower version (5.3.3) compared to localhost (5.5.9) the following error is generated:

  

syntax error, unexpected '[' in

To correct this you need to convert to the old syntax, this can be with a replace from your IDE / text editor copy the excerpt from the array, then replace [ with array( and ] with ) do not forget to $total who is also an array.

Syntax php5.4

$convidados = [
    'Cieli' => [0,15],
    'Carlinhos' => [0,30]
];

Syntax for previous versions:

$convidados = array(
    'Cieli' => array(0,15),
    'Carlinhos' => array(0,30)
);

In the example (sandbox) you can run the code in different versions of php. See your converted code by running the phpfiddle where the php version is 5.3.29.

    
07.03.2015 / 00:22