PHP Code Version Dependency

In each version of php, new functions are added and some functions are stopped.

Example:

<?php
$hex = hex2bin("6578616d706c65206865782064617461");
var_dump($hex);
?>

php 5.4.0 and above will be required since hex2bin was introduced in php 5.4.0.
Satisfactorily check version dependencies manually in php.net for each built-in function used in PHP code. Is there any automated / semi-automated way to determine the minimum version (and maximum version, if applicable) of php installation to execute any given php code?

+2
source share
5 answers

PHPCompatibility: https://github.com/wimg/PHPCompatibility 5.2, 5.3, 5.4 5.5 (alpha2 )

+1

, php, , "function_exists", , php .

http://php.net/manual/en/function.function-exists.php

<?php
if (function_exists('hex2bin')) {
    echo "hex2bin function is available.<br />\n";
} else {
    echo "hex2bin function is not available.<br />\n";
}
?>
+2

/ /.

Composer , , .

+2

, . , .

if ( ! function_exists('hex2bin')) {
    function hex2bin($hexstr)
    {
        $n = strlen($hexstr);
        $sbin="";  
        $i=0;
        while($i<$n)
        {      
            $a =substr($hexstr,$i,2);          
            $c = pack("H*",$a);
            if ($i==0){$sbin=$c;}
            else {$sbin.=$c;}
            $i+=2;
        }
        return $sbin;
    }
}

Johnson.

Setting up an important function that does the same as the new ones, if they do not exist, allows you to do your business without fear of inability. Just hide them when you have no reason to edit them, and they will not bother you either.

+1
source

You can create a manual check, and then use the patch. To determine what is missing.

Using phpversion ();

 if (strnatcmp(phpversion(),'5.2.10') >= 0) 
 { 
       //loading patch

 } 
 else 
 { 
     //loading patch
      function abc(){
        //
      }
 } 
+1
source

All Articles