php 7.2 一些注意事项.

2018-01-20 20:18:41
<?php$b = array();each($b);// Deprecated:  The each() function is deprecated. This message will be suppressed on further calls

复制代码

each 函数 在php7.2已经设定为过时, 

<?phpcount('');// Warning:  count(): Parameter must be an array or an object that implements Countable

count 函数在php7.2将严格执行类型区分.  不正确的类型传入, 会引发一段警告. 

复制代码

<?php$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');echo "New anonymous function: $newfunc\n";echo $newfunc(2, M_E) . "\n";// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599

// Warning This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.

复制代码

create_function 函数在php7.2已经设定为过时.

 

-----------------------------------------------------------------------------------------------------------

解决方法: 

复制代码

function fun_adm_each(&$array){   $res = array();   $key = key($array);   if($key !== null){       next($array); 
       $res[1] = $res['value'] = $array[$key];       $res[0] = $res['key'] = $key;
   }else{       $res = false;
   }   return $res;
}

复制代码

替代each.

 

复制代码

function fun_adm_count($array_or_countable,$mode = COUNT_NORMAL){    if(is_array($array_or_countable) || is_object($array_or_countable)){        return count($array_or_countable, $mode);
    }else{        return 0;
    }
}

复制代码

替代count.

 

<?php    $fun = function ($str ){echo $str}    $fun('Yuan');

替代create_function. 

 

END

 


  • 2020-03-04 13:00:23

    NPM酷库:minimist,命令行参数解析

    昨天我们了解的dotenv库用于从文件中加载环境变量。环境变量用于程序运行时动态加载参数,除了环境变量,我们还可以在启动Node.js 程序时直接指定命令行参数:

  • 2020-03-04 21:01:26

    window自带截屏功能

    我们习惯了QQ和微信截图,当我们没有打开微信和QQ的时候,我们想用截图怎么版,当然是,打开QQ和微信,哈哈?

  • 2020-03-05 13:12:54

    Markdown的css样式

    本样式在这个样式的基础上做了一些修改, 主要是对于表格和代码块以及一些细节的修改。 主要目的是用在chrome的扩展 Markdown Preview Plus中, 替换其内置的样式。 由于 Markdown Preview Plus对css文件大大小有要求(小于8K), 所以需要使用压缩后的 css 文件。 当然也可以作为一个单独的markdown样式来使用。

  • 2020-03-06 22:28:05

    git中submodule子模块的添加、使用和删除

    执行成功后,git status会看到项目中修改了.gitmodules,并增加了一个新文件(为刚刚添加的路径) git diff --cached查看修改内容可以看到增加了子模块,并且新文件下为子模块的提交hash摘要 git commit提交即完成子模块的添加