欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          總結(jié)PHP升級7.2之后需要注意的事情

          總結(jié)PHP升級7.2之后需要注意的事情

          最近升級了PHP版本,從7.1升級到7.2,升級前版本:

          PHP 7.1.14 (cli) (built: Feb 2 2018 08:42:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.14, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

          升級后版本:

          PHP 7.2.2 (cli) (built: Feb 24 2018 17:51:12) ( ZTS DEBUG ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.2, Copyright (c) 1999-2018, by Zend Technologies

          推薦(免費):PHP7

          升級完成之后發(fā)現(xiàn)有幾個框架在使用時都出現(xiàn)了問題,主要原因集中在7.2之后廢棄了一些功能,下面列出幾個常見的問題:

          1、each函數(shù)已被廢棄:

          之前版本寫法:

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

          在7.2版本中會提示過時,可以使用foreach替代each方法,也可以自己修改each方法替代:

          <?php     function func_new_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;     }

          2、當(dāng)傳遞一個無效參數(shù)時,count()函數(shù)將拋出warning警告:

          之前版本寫法

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

          在7.2版本中將嚴(yán)格執(zhí)行類型區(qū)分,參數(shù)類型不正確,將會出現(xiàn)警告,所以需要在使用count方法時注意參數(shù)的值,不過也可以通過自己修改方法來替代(不建議):

          <?php     function func_new_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;         }     }

          3、create_function被廢棄,可以用匿名函數(shù)來代替:

          之前版本寫法:

          <?php     $newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');    echo "New anonymous function: $newfuncn";    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.

          在7.2版本中會有警告提示,可修改為匿名函數(shù)來替代:

          <?php     $newfunc = function ($a,$b){         return "ln($a) + ln($b) = " . log($a * $b);     };    echo $newfunc(2, M_E) . "n";

          贊(0)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號