简体   繁体   English

语法在localhost上运行,而不在godaddy服务器上运行

[英]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_modelget_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.

相关问题 WordPress活动日历PHP在Godaddy服务器上不起作用,但在WAMP本地主机中起作用 - WordPress Events Calendar PHP not working on Godaddy server, but works in WAMP localhost PHPMailer 无法在 Godaddy 服务器上运行 - PHPMailer is not working on godaddy server PDO无法在GoDaddy服务器中运行 - PDO not working in GoDaddy Server PHP重定向或cookie,不适用于Godaddy,但适用于localhost - PHP Redirects, or cookies, not working on Godaddy, but working on localhost 在 Godaddy 上移动上传的文件不起作用(但在本地主机上工作) - Move Uploded file is not working, on Godaddy (but Working on localhost) ob_flush()在localhost上工作但在GoDaddy没有在线工作 - ob_flush() working on localhost but not online at GoDaddy 301重定向在GoDaddy服务器上不起作用 - 301 Redirects are not working on GoDaddy server 在Godaddy服务器前端上无法在CodeIgniter中工作 - On godaddy server frontend not working in CodeIgniter .htaccess文件在godaddy服务器上不起作用 - .htaccess file not working on godaddy server 填充php数组变量不适用于godaddy服务器(php版本5.3.24)在localhost中完美运行 - populating php array variable is not working in godaddy server(php version 5.3.24) works perfectly in localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM