Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

PHP 5.4 vs 5.3 app errors

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'] = '';

which is causes this error

 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

change:

$data = [];

to

$data =array();

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...