[英]Syntax working on localhost, not working on godaddy server
Can someone tell me why this code would work on my local server but not with godaddy? 有人可以告诉我为什么此代码在我的本地服务器上可以运行,但在Godaddy上不能运行吗? I get the following error on godaddy...
我在Godaddy上收到以下错误...
Parse error: syntax error, unexpected '[' in /home/content/20/10592020/html/foodport/application/controllers/register.php on line 41
Here is the get_userId
function from my user_model
. 这是我的
user_model
的get_userId
函数。
public function get_userId(){
$results = $this->obtain_user_info('users', array('username'=>$this->username), true);
if(count($results) > 0)
{
return $results;
}else
{
return array("user_id" => GUEST_ID);
}
}
Here is the obtain_user_info
function: 这是
obtain_user_info
函数:
private function obtain_user_info($table, $params, $assoc = false){
$query = $this->db->get_where($table, $params);
if(!$assoc){
$results = $query->result();
}else
{
$results = $query->row_array();
}
return $results;
}
Here is the code in my register controller specifically line 41. 这是我的寄存器控制器中第41行的代码。
$user_id = $user->get_userId()['user_id'];
Check the version of PHP - my guess is that your local server is running a later version than GoDaddy's server. 检查PHP的版本-我的猜测是您的本地服务器运行的版本比GoDaddy的服务器更高。 You might have to do something like this:
您可能需要执行以下操作:
$temp_id = $user->get_userId();
$user_id = $temp_id['user_id'];
Specifically, you need PHP > 5.4.0 to access a function return array directly like: 具体来说,您需要PHP> 5.4.0才能直接访问函数返回数组,例如:
$user_id = $user->get_userId()['user_id'];
Prior to 5.4.0 you would need to assign the return of the function to a variable and access it: 在5.4.0之前,您需要将函数的返回值分配给变量并访问它:
$result = $user->get_userId();
$user_id = $result['user_id'];
But I would ask, why return an array if you are only returning one value? 但是我会问,如果只返回一个值,为什么要返回一个数组?
$user_id = $user->get_userId()['user_id'];
http://php.net/manual/en/language.types.array.php#example-88 http://php.net/manual/en/language.types.array.php#example-88
This is Array dereferencing which is available in php 5.4 However usually godaddy got php 5.3.3 这是数组取消引用,在php 5.4中可用,但是通常godaddy都得到了php 5.3.3
Depending on your hosting plan you can change it. 您可以根据自己的托管计划进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.