skip to Main Content

I am migrating to the latest 7.3 and would like to get in all the code before actually migrating. 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. So, I created a function in the mean time is_countable_temp($temp) which just returns 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.

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.
    }

2

Answers


  1. You can get the php version like described here and compare it with version compare:

    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 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?

    Login or Signup to reply.
  2. if (version_compare(phpversion(), '7.3', '>='))
    {
           //do something
    }
    else
    {
           return false;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search