Parse error in syntax when I upload a package

Permalink
Hello - I have had a package that I was working on - work perfectly until I uploaded it now it throws a parse error;


Parse error: syntax error, unexpected '[' in /home/socctron/public_html/packages/predictions/models/teams.php on line 15


model -

class Teams extends Model {
    var $_table = 'SoccerTeams';
     public static function getTeamsSelect()
    {
       $query = 'SELECT id, team_name
            FROM SoccerTeams
            ORDER BY team_name';
        $db = Loader::db();
        $r = $db->Execute($query);
        $records = [];
        while ($row = $r->FetchRow()) {
            $records[] = $row;
        }
        return $records;
    }


team controller -

<?php 
defined('C5_EXECUTE') or die("Access Denied.");
class DashboardTeamsAddController extends Controller {
   public function save() {
      Loader::model('teams','predictions');
      $team = new Teams();
      if ($this->post('id')) {
         $team->load('id = ?', $this->post('id'));
      }
      $team->team_name = $this->post('team_name');
      $team->team_description = $this->post('team_description');
      $team->site_url = $this->post('site_url'); 
      $team->replace();
      $this->redirect('/dashboard/teams');
   }


Not sure why it has parse code error problem now.
Have been adding, editing, saving on local copy for weeks with no problems

INTcommunications
 
INTcommunications replied on at Permalink Reply
INTcommunications
Getting another parse error that is probably related to the same function:

Parse error: syntax error, unexpected '[' in /home/socctron/public_html/packages/predictions/controllers/dashboard/predictions/add_predictions.php on line 10

This where I call the function ( in the team model ) to populate the selectbox in the form -

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
class DashboardPredictionsAddPredictionsController extends Controller {
    public function view(){
      Loader::model('Teams','predictions');
      $teams = Teams::getTeamsSelect();
$categorySelection = [0 => 'Choose Team']; //pre-populate with a blank option
foreach($teams AS $t){
    $categorySelection[$t['id']] = $t['team_name'];
}
$this->set('categorySelection', $categorySelection);  
    $this->set('HeadMessage', 'Add New Predictions');
        $user = new User();
        $theUser = $user->getUserName();
           $this->set ('created_by_name' , $theUser);


the error is in the choose team part. Again this error does not happen on my local copy - just on the one online. So it is very hard to fix.
JohntheFish replied on at Permalink Reply
JohntheFish
I suspect you have an older version of php on the server than on your dev system.

Try replacing
$list = [];


with
$list = array();


And similar for assignments with values.
INTcommunications replied on at Permalink Reply
INTcommunications
Changing
$records = [];
to
$records = array();

Seems to throw new errors. Is the above the correct syntax JohntheFish?
INTcommunications replied on at Permalink Reply
INTcommunications
JohntheFish
You are right about my local PHP being newer version
local development php is 5.5.10

Web server is 5.3.26

So this model should be changed from-

class Teams extends Model {
var $_table = 'SoccerTeams';
public static function getTeamsSelect()
{
$query = 'SELECT id, team_name
FROM SoccerTeams
ORDER BY team_name';
$db = Loader::db();
$r = $db->Execute($query);
$records = [];
while ($row = $r->FetchRow()) {
$records[] = $row;
}
return $records;
}


to


class Teams extends Model {
var $_table = 'SoccerTeams';
public static function getTeamsSelect()
{
$query = 'SELECT id, team_name
FROM SoccerTeams
ORDER BY team_name';
$db = Loader::db();
$r = $db->Execute($query);
$records = array();
while ($row = $r->FetchRow()) {
$records array() = $row;
}
return $records;
}


?
JohntheFish replied on at Permalink Reply
JohntheFish
array() cant be used on the left of an assignment.

If you edit your post to add [ code ] etc, I will be able to read it more clearly.
INTcommunications replied on at Permalink Reply
INTcommunications
Sorry - here it is again-

class Teams extends Model {
var $_table = 'SoccerTeams';
public static function getTeamsSelect()
{
$query = 'SELECT id, team_name
FROM SoccerTeams
ORDER BY team_name';
$db = Loader::db();
$r = $db->Execute($query);
$records = [];
while ($row = $r->FetchRow()) {
$records[] = $row;
}
return $records;
}

to

class Teams extends Model {
var $_table = 'SoccerTeams';
public static function getTeamsSelect()
{
$query = 'SELECT id, team_name
FROM SoccerTeams
ORDER BY team_name';
$db = Loader::db();
$r = $db->Execute($query);
$records = array();
while ($row = $r->FetchRow()) {
$records array() = $row;
}
return $records;
}

?

There is another place where the same error occurs - the categorySelection = [0=> 'choose Team'];
line

seems to be the same issue.
public function view(){
      Loader::model('Teams','predictions');
      $teams = Teams::getTeamsSelect();
$categorySelection = [0 => 'Choose Team']; //pre-populate with a blank option
foreach($teams AS $t){
    $categorySelection[$t['id']] = $t['team_name'];
}
$this->set('categorySelection', $categorySelection);  
    $this->set('HeadMessage', 'Add New Predictions');
        $user = new User();
        $theUser = $user->getUserName();
           $this->set ('created_by_name' , $theUser);
    }


This is really frustrating as my development PHP version I have reloaded with the same version of PHP - and I can't recreate the errors - Is there something else that may be running on my Mamp Pro that is not on the server that would affect syntax with arrays?
INTcommunications replied on at Permalink Reply
INTcommunications
now the errors are


Warning: require_once(/home/socctron/public_html/packages/predictions/models/Teams.php) [function.require-once]: failed to open stream: No such file or directory in /home/socctron/public_html/updates/concrete5.6.2.1_updater/concrete/core/libraries/loader.php on line 48

Fatal error: require_once() [function.require]: Failed opening required '/home/socctron/public_html/packages/predictions/models/Teams.php' (include_path='/home/socctron/public_html/libraries/3rdparty:/home/socctron/public_html/updates/concrete5.6.2.1_updater/concrete/libraries/3rdparty:.:/usr/lib/php:/usr/local/lib/php') in /home/socctron/public_html/updates/concrete5.6.2.1_updater/concrete/core/libraries/loader.php on line 48
INTcommunications replied on at Permalink Reply
INTcommunications
I see that array short syntax was added with php 5.4
http://php.net/manual/en/migration54.new-features.php...

This is probably the cause of all my problems. I am going to have to update php on my web server or change hosts