close

最近有一台主機升級到 PHP 8 了,陸續遇到一些需要調整的東西。之前忘了記下來,現在又遇到一次,又查了一遍,趕快補一下。Orz


在不同版本的 PHPmailer 可能需要做的調整:

  1. 配合 PHP 8 停止支援 __autoload(),改用 sql_autoloaod_register()
    • 錯誤訊息:PHP Fatal error:  __autoload() is no longer supported, use spl_autoload_register()
    • 原本在 PHPMailerAutoload.php 的寫法為:
      function __autoload($classname)
      改寫為:
      function spl_autoload_register($classname)
       
  2. 配合 PHP 8 停用 each(),改用 foreach()
    • 錯誤訊息:PHP Fatal error:  Uncaught Error: Call to undefined function each()
    • 原本在 class.smtp.php 的寫法為:
      while(list(, $line) = @each($lines)) {
      改寫為:
      foreach ($lines as $line) {
      (以此類推)
       

在 PHP 8 要對 PHPExcel 做的調整:

  1. 陣列元素不可再使用大括號 {} 操作,需要使用中括號 []
    • 錯誤訊息:PHP Fatal error:  Array and string offset access syntax with curly braces is no longer supported
    • 原本在 PHP 7 的寫法為:
      $str = array(1, 2, 3);
      $test = $str
      {0};
      改寫為:
      $str = array(1, 2, 3);
      $test = $str
      [0];
       
  2. DefaultValueBinder.php 出現 "Trying to access array offset on value of type int",依照  stackoverflow 的上的討論,我將第 86 行由:
    } elseif ($pValue[0] === '=' && strlen($pValue) > 1) {
    改為:
    } elseif (0 === strpos($pValue, '=') && strlen($pValue) > 1) {

 

 

 

arrow
arrow
    文章標籤
    PHP8 PHP
    全站熱搜

    小攻城師 發表在 痞客邦 留言(0) 人氣()