duanreng3439
duanreng3439
2014-04-29 22:09
浏览 59
已采纳

Debian PHP 5.4.27与Ubuntu PHP 5.4.16

Well, I'm transferring a little web server from one computer to other, on the 'other' computer I cannot a more updated version of PHP,

I just have to add my files through ssh and that's all, when I load my webpage it says explicitly:

The error is showing on a Debian with PHP 5.4.27 squeeze, the webserver comes from an Ubuntu with PHP 5.4.16 oneiric

Parse error: syntax error, unexpected '[' in ~directory~ on line 38

This is the line 38.

$VALUE=$DB->query("a nice sentence")->fetch()[0];

So, i was pretty surprised because PDO was accepted since PHP 5.1, so, i look deeper and i found the possible error, you can't simply do ->fetch()[0], you must separate it in order to be "processed",

However, I have transport this server with this information before, so i really don't know if it's something on the configuration of PHP or maybe the version by itself 5.4.X? You guys know any hint? As I said, i can't just install other updated version of PHP5, what do you recommend?

Have a nice night.

Edit: updated to the issue on the PHP 5.4 now

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongye1942
    dongye1942 2014-04-30 13:07
    已采纳

    Apparently, the error was solved by JUST changing the first issue line (the other hundreds of codes that had that wasn't necessary to change, what i believe to be a little weird).

    $VALUE = $DB->query("a nice sentence")->fetch()->offset(0);
    
    点赞 评论
  • duanji2772
    duanji2772 2014-04-29 22:56

    The error seems triggered by the array dereferencing. This was added in PHP 5.4.. Not sure how you made that work in 5.3.6

    http://nl3.php.net/language.types.array.php

    To workaround you could try

    $VALUE = $DB->query("a nice sentence")->fetch();
    echo $VALUE[0];
    
    点赞 评论
  • douman6679
    douman6679 2014-04-30 11:21

    PHP Version on my ubuntu (where it works):

    PHP Version 5.4.16
    

    PHP Version on the Debian (where it does not work):

    PHP Version 5.4.27-1~dotdeb.0
    

    This version number was extracted by using phpinfo(); on the index page.

    点赞 评论

相关推荐