PHP 5.4 vs 5.3应用程序错误 [英] PHP 5.4 vs 5.3 app errors

查看:63
本文介绍了PHP 5.4 vs 5.3应用程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用php构建一个Web应用程序,并在php 5.4中构建它.但是,我只是意识到我的服务器只能运行5.3或5.2.在我的控制器文件中,我有这行代码

I am building an web app with php and built it in php 5.4. However, I just realized my server run only 5.3 or 5.2. In my controller file I have this line of code

        $this->load->model('admin/upholstery_category_admin');
    $this->load->helper('url');

    if($method == 'add')
    {
        $categories = $this->db->get('category')->result();
line 158 here>>     $data = [];
        $data['cats'] = $categories;
        $data['message'] = '';

这是导致此错误的原因

 Parse error: syntax error, unexpected '[' in /home/content/51/6663351/html/application/controllers/admin.php on line 158

如何更改语法以更正此错误?

How do i change the syntax to correct this?

推荐答案

更改:

$data = [];

$data =array();

从PHP 5.4开始,您还可以使用短数组语法,该语法用[]替换array().因此,仅在5.4及更高版本中使用

As of PHP 5.4 you can also use the short array syntax, which replaces array() with []. So its only with 5.4 and later

这篇关于PHP 5.4 vs 5.3应用程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆