donvo24600 2015-09-23 00:20
浏览 94
已采纳

php version_compare()在localhost上失败,在服务器上运行

This conditional code execution if statement is right out of the php manual:

// version_compare ( string $version1 , string $version2 [, string $operator ] )
// http://php.net/manual/en/function.version-compare.php
if (version_compare(PHP_VERSION, '5.3.0') >= 0)
{
    //echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "
";
    include_once( DOMAIN_PATH . "sitewide/functions/make_comparer.php" );
    usort($market_and_volume, make_comparer(['exchange_volume', SORT_DESC], ['exchange', SORT_DESC]));   
}

The above code runs free of error on the production server. On localhost php version 5.2.9-2 which theoretically fails the version_compare() function it throws an error:

Parse error: parse error, expecting `')'' in test.php on line 61

Normally i might not care since its running on the 5.4.39 production server, however I plan to use this snippet on almost every localhost page which as it stands would impede future development.

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongzhunqiu4841 2015-09-23 00:25
    关注

    The problem is you are using the shorthand array notation. [...]. Unfortuantely this is only supported from PHP 5.4.0 and up. Even though the "bad" code is never run it fails to compile so throws an error.

    This can be fixed by using the array(...) notation like so.

    // version_compare ( string $version1 , string $version2 [, string $operator ] )
    // http://php.net/manual/en/function.version-compare.php
    if (version_compare(PHP_VERSION, '5.3.0') >= 0)
    {
        //echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "
    ";
        include_once( DOMAIN_PATH . "sitewide/functions/make_comparer.php" );
        usort($market_and_volume, make_comparer(array('exchange_volume', SORT_DESC), array('exchange', SORT_DESC)));   
    }
    

    REFERENCE: http://php.net/manual/en/language.types.array.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?