简体   繁体   English

迁移到php7.3如何检查php版本

[英]Migrating to php7.3 how to check for php version

I am migrating to the latest 7.3 and would like to get in all the code before actually migrating.我正在迁移到最新的 7.3,并希望在实际迁移之前获取所有代码。 I need to use the function is_countable which is new to 7.3 so it will throw an error on my existing site running on 7.2.我需要使用 7.3 新增的 function is_countable,因此它会在我在 7.2 上运行的现有站点上引发错误。 So, I created a function in the mean time is_countable_temp($temp) which just returns TRUE.因此,我同时创建了一个 function is_countable_temp($temp),它只返回 TRUE。

What I would like to do is check the version and if it is greater then or equal to 7.3 then use the actual is_counbable function else just return true.我想做的是检查版本,如果它大于或等于 7.3,然后使用实际的 is_counbable function 否则只返回 true。

enter code here

    function is_countable_temp($temp) {
       // if version is 7.3 or greater then call the is_countable function else just return true.
    }

You can get the php version like described here and compare it with version compare :您可以获得 php 版本,如下所述并将其与版本比较进行比较

function is_countable_temp($temp) {
    return version_compare(phpversion(), '7.3', '>=') 
               ? is_countable($temp) 
               : true;
}

But you could also achieve the desired functionality with function_exists('is_countable') , so:但是您也可以使用function_exists('is_countable')实现所需的功能,因此:

function is_countable_temp($temp) {
    return function_exists('is_countable') 
               ? is_countable($temp) 
               : true;
}

And you are aware that we are at version 8 already, right?你知道我们已经是第 8 版了,对吧?

if (version_compare(phpversion(), '7.3', '>='))
{
       //do something
}
else
{
       return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM