So this is my first time trying to install and use composer and other packages. I installed composer and slim 3 on my localhost, and it is working just fine.
I then went ahead and installed it with SSH on my remote server. No errors occurred, and all files are there. And in my composer.json file slim is there as well. I have a autoload file.
But when I try to start writing some code, it's like they are not even installed and I get a error like this as an example.
Parse error: syntax error, unexpected '[', expecting ')' in /domainName/public/bootstrap/app.php on line 6.
This is my app.php file
<?php
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new \Slim\App([
'settings' => [
'displayErrorDetails' => true,
]
]);
$app->get('/', function($request, $response){
return 'Home';
});
And this is my index.php file
<?php
namespace App;
require __DIR__ . '/../bootstrap/app.php';
$app->run();
Very basic code to just test and see if it worked, which it does not. After spending many hours on Google I can't find a solution, and all help here will be much appreciated.
As it's working fine locally, but not on the remote server - PHP 5.4 introduced the syntax of square brackets for arrays.
In PHP 5.3 for example, you had to do:
$array = array( 'foo' => 'bar' );
From PHP 5.4 onwards, a short syntax could be used of:
$array = [ 'foo' => 'bar' ];
I'd suggest that the issue you are hitting is that the version of PHP on the server may be an older version than your local pc.