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

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

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?