Parse error on server, works on localhost

I got a few lines of code that run well on my localhost with PHP Version 5.4.19 but doesn't seem to work on a server that runs 5.3.3. On my server I get the following error:

Parse error: syntax error, unexpected '[', expecting ',' or ';' in /var/www/html/newpage.php on line 147

The code that seems to be giving the error is:

    146.    <a href=faq.php?id=<?php echo $systemId ?> class="menuitem">FAQ</a>
    147.    <a href="<?php echo getLink($systemId,'map1')['link'];?>" class="menuitem">Test</a>
    148.    <a href="<?php echo getLink($systemId,'map2')['link'];?>" class="menuitem">Test1</a>
    149.    <a href="<?php echo getLink($systemId,'map3')['link'];?>" class="menuitem">Test2</a>
    150.    <a href="<?php echo getLink($systemId,'list')['link'];?>" class="menuitem">Test3</a>
    151.    <a href="<?php echo getLink($systemId,'map4')['link'];?>" class="menuitem">Test4</a>
    152.    <a href="index.php" class="menuitem">Frontpage</a>

The function called in the above code (getLink) looks like this:

function getLink($id, $category){
    $category = mysql_real_escape_string($category);
    $id = mysql_real_escape_string($id);
    $result = mysql_query("SELECT * FROM `links` WHERE `category` = '$category' AND `text_id` = '$id'");
    return mysql_fetch_assoc($result);
}

The function getLink should work well and the database is populated. I've tried to do some var_dump() on getLink but the Parse error seem to override that code?

Anyone got any idea where the error might be?


You cannot directly use <?php echo getLink($systemId,'map1')['link'];?> in PHP < 5.4.

You must do something like that, or upgrade your server's PHP version :

<?php $l = getLink($systemId,'map1'); echo $l['link']; ?>

你需要PHP 5.4或更高版本

Function array dereferencing has been added, e.g. foo()[0].
链接地址: http://www.djcxy.com/p/69546.html

上一篇: 意外的错误

下一篇: 解析服务器错误,在localhost上运行