我正在使用Codeigniter 3.0.6。我正在我的本地服务器上开发,我的PHP版本已经是php7。它运作良好。但后来我把它上传到使用php 5.6的服务器上。然后我收到了这个错误。
Parse error: syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING) in /var/www/simimi/application/controllers/Student.php on line 53 A PHP Error was encountered Severity: Parsing Error Message: syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING) Filename: controllers/Student.php Line Number: 53 Backtrace:
这是我的控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Student extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('m_student','sdb');
$this->load->model('m_student_profile','sdb_pro');
$this->load->model('m_student_academic','sdb_aca');
$this->load->model('m_student_immigration','sdb_imm');
$this->load->model('m_student_emergency','sdb_eme');
$this->cname = 'student';
$this->menu = 'Student';
$this->fitur = '';
$this->active_user=get_nama_user();
$this->active_username=get_username();
$this->active_privilege=get_hak_akses();
if(!cek_auth())
{
flash_err('Authorization needed.');
redirect(base_url('auth'));
}
if(!cek_fitur('student_list'))
{
flash_err("You don't have privilege to use `{$this->menu}` feature.");
redirect(base_url('dashboard'));
}
}
public function index()
{
$this->list();
}
public function action($func='', $id=0)
{
if(!empty(trim($func)))
{
if(!empty($id))
$this->$func($id);
else if(empty($id))
$this->$func();
}
else
{
flash_err("You don't have permission.");
redirect(base_url($this->cname));
}
}
public function list()
{
$data['title']='Student';
$data['subtitle']='List';
$data['active']='student_list';
$this->fitur = 'List';
$data['content']='student_list';
$data['students']=$this->sdb->get_list();
$this->load->view('template/template',$data);
}
}
Aaaaand 我刚刚发现列表不允许作为方法名称。我想知道它为什么会在php7上运行。
答案 0 :(得分:2)
这是因为list
是PHP的保留关键字。在PHP 7之前,您不能将它们用作方法名称。
http://www.php.net/manual/en/reserved.keywords.php
从PHP 7.0.0开始,这些关键字被允许作为类,接口和特征的属性,常量和方法名称,除了该类不能用作常量名称。
答案 1 :(得分:0)
结果列表不允许是方法名称。我更改了方法名称,现在效果很好。虽然我仍然想知道为什么它在php7上运行良好。