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

 


  • 2021-01-16 09:49:13

    Cocoapods如何查看项目中引入库的版本号

    项目中已经安装过Cocoapods,并生成了Podfile.lock文件。 打开终端,cd命令切换到项目中的Podfile.lock文件目录下,执行命令:cat Podfile.lock 即可。也可以用文本方式打开 Podfile.lock 文件。示例如下:

  • 2021-01-18 13:50:21

    vue实现粘贴功能

    paste事件就是粘贴事件 需要通过clipboardData获得粘贴的内容

  • 2021-01-18 15:12:57

    flex和inline-flex区别

    flex: 将对象作为弹性伸缩盒显示 inline-flex:将对象作为内联块级弹性伸缩盒显示

  • 2021-01-21 13:52:36

    node.js使用Nodemailer发送邮件

    常常看到一些网站有邮箱获取验证码验证注册或者修改密码等,今天也来了解一下在nodejs + express怎么发送电子邮件。使用模块Nodemailer。这里以qq邮箱举例子。