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

 


  • 2017-11-28 14:57:19

    vagrant up 失败解决办法

    直接使用VirtualBox开启一个vm也会失败,基本上可以确定是VirtualBox版本的问题 有遇到过安装了VirtualBox-5.0.22-108108-Win.exe的版本在win7下用不了,卸载重装VirtualBox-4.3.12-93733-Win.exe之后可用。

  • 2017-12-05 22:30:02

    php7.0升级php7.2

    看电脑上的教程要备份7.0配置文件以及扩展啥的,我感觉不如卸载干净重新安装

  • 2017-12-06 09:35:10

    分页优化的四种方式

    在大数据量的情况下,原本很简单的分页如果没有处理好,你会发现分页的请求会消耗你大量的数据库时间。如果你遇到了这个问题,文章给了你几个很好的解决的方案。当然,初学者若能看完这篇文章,那么它会指导你写出更具有扩展性的分页代码。