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

 


  • 2018-01-08 22:12:20

    加快gradle的编译速度总结-亲身经历

    这两题集成mob的maven,这个编译速度是慢的可怜啊,经过百度得出了这样一个方案,配置好以后那可是神速啊,妈妈再也不用担心我的编译速度看。嗷嗷的。

  • 2018-01-11 09:07:01

    微信小程序的组件用法与传统HTML5标签的区别

    小程序刚开放公测,互联网圈内开始了各种解读和猜测。其中有观点认为小程序和HTML5有着紧密关联,甚至小程序就是基于HTML5开发。 经过仔细研究文档和代码开发,从视图层的角度来说,小程序与传统HTML5还是有明显的区别,主要区别在于: