zoukankan      html  css  js  c++  java
  • php 7.2 一些注意事项.

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

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

    <?php
    
    count('');
    
    // 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
    ";
    echo $newfunc(2, M_E) . "
    ";
    // 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

  • 相关阅读:
    Redis计数信号量
    一台服务器能支撑多少个TCP连接
    Python常见字符编码间的转换
    浅谈HttpDNS
    用Python写的一个MySQL数据库监测系统
    用Python写的一个MySQL数据库监测系统
    how tomcat works(第九章)
    how tomcat works(第八章)
    how tomcat works(第八章)
    how tomcat works(第九章)
  • 原文地址:https://www.cnblogs.com/phpnew/p/7991572.html
Copyright © 2011-2022 走看看