Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP代码版本依赖关系_Php_Dependencies_Version - Fatal编程技术网

PHP代码版本依赖关系

PHP代码版本依赖关系,php,dependencies,version,Php,Dependencies,Version,在每一个php版本中,都会添加一些新特性,并停止一些特性 例如: <?php $hex = hex2bin("6578616d706c65206865782064617461"); var_dump($hex); ?> 需要PHP5.4.0及以上版本,因为PHP5.4.0中引入了hex2bin。 在php.net中手动检查php代码中使用的每个内置函数的版本依赖关系是非常繁琐的。是否有任何自动/半自动的方法来确定执行任何给定php代码所需的php安装的最低版本(以及最高版本,如

在每一个php版本中,都会添加一些新特性,并停止一些特性

例如:

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

需要PHP5.4.0及以上版本,因为PHP5.4.0中引入了hex2bin。

在php.net中手动检查php代码中使用的每个内置函数的版本依赖关系是非常繁琐的。是否有任何自动/半自动的方法来确定执行任何给定php代码所需的php安装的最低版本(以及最高版本,如果适用)?

不知道是否有方法检查需要哪个版本的php,但您可以使用“function\u exists”查看您的php版本是否具有该功能


由程序员来说明他或她的库/项目的依赖关系


许多项目现在用作依赖项管理器,但对于遗留代码,除了运行它和发誓反对错误之外,您不能做太多事情。

好的做法可能是有回退。正如在中提到的,还有其他选择

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;
    }
}
如果(!函数_存在('hex2bin')){
函数hex2bin($hexstr)
{
$n=strlen($hexstr);
$sbin=“”;
$i=0;

而($i您可以创建一个手动检查,然后使用“补丁”。来定义缺少的内容

使用phpversion()


查看PHPCompatibility项目:
这将测试您的代码与5.2、5.3、5.4和5.5(撰写本文时为alpha2)的兼容性。

我没有找到我想要的,我接受了这个答案,因为它是最合适的答案。或者只是查看自述文件中的“需求”部分;)
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;
    }
}
 if (strnatcmp(phpversion(),'5.2.10') >= 0) 
 { 
       //loading patch

 } 
 else 
 { 
     //loading patch
      function abc(){
        //
      }
 }