Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated.

Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated.

WordPressをデバッグモードにしたら出たエラー。

 

Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /hogehoge/public_html/wp-content/themes/hoge/functions.php on line 14

 

php7.4から、明示的に括弧で囲わずに三項演算子をネストすると
deprecatedが発生するようになりました。
参考サイト:PHP7.4の変更点 | GMOアドパートナーズ TECH BLOG byGMO

 

▼修正前

$str = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";

 

▼修正後
三項演算子は読みづらいので中括弧使ってインデントするようにしました。

if( empty($_SERVER["HTTPS"]) ){
  $str = '';
}else{
  if( $_SERVER["HTTPS"] == "on" ){
      $str = 's';
  }else{
      $str = '';
  }
}

WordPressカテゴリの最新記事