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 -
team controller -
Not sure why it has parse code error problem now.
Have been adding, editing, saving on local copy for weeks with no problems
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; }
Viewing 15 lines of 16 lines. View entire code block.
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'); }
Viewing 15 lines of 22 lines. View entire code block.
Not sure why it has parse code error problem now.
Have been adding, editing, saving on local copy for weeks with no problems
I suspect you have an older version of php on the server than on your dev system.
Try replacing
with
And similar for assignments with values.
Try replacing
$list = [];
with
$list = array();
And similar for assignments with values.
Changing
$records = [];
to
$records = array();
Seems to throw new errors. Is the above the correct syntax JohntheFish?
$records = [];
to
$records = array();
Seems to throw new errors. Is the above the correct syntax JohntheFish?
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;
}
?
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;
}
?
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.
If you edit your post to add [ code ] etc, I will be able to read it more clearly.
Sorry - here it is again-
to
?
There is another place where the same error occurs - the categorySelection = [0=> 'choose Team'];
line
seems to be the same issue.
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?
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?
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
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
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
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
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 -
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.