2015-11-07 62 views
0

我剛換了一堆WordPress的託管網站的服務器。在舊的服務器上,我們有5.3版本的PHP,在新的版本上有5.4.33。問題是我們在這次改變後收到很多錯誤,並且有些錯誤對我來說很難解決。看看下面的代碼,請:)從php 5.3升級到5.4.33後wordpress主題錯誤

這是我得到的錯誤:

  1. 注意:未定義的變量:在/可溼性粉劑內容圖標/主題/比分/庫/職能 - 上線單match.php 138

  2. 說明:未定義變量:在圖像上/wp-content/themes/livescore/library/functions-single-match.php管線145

  3. 說明:未定義變量:在/wp-content/themes/livescore/library/functions-single-match.php圖標上線179

  4. 說明:未定義變量:圖像/可溼性粉劑內容/主題/比分/庫/函數單match.php上線184

這是下面的功能單match.php:

<?php 

function lastMatches($teamName, $directTeam = '') 

{ 

    global $wpdb_mysqli; 

    $matches = array(); 

    if ($directTeam) 

    { 


     $args = array(

      'post_type' => 'matches', 

      'post_status' => 'publish', 

      'posts_per_page' => 10, 

      'meta_query' => array(

       array(

        'key' => '_live_echipa_gazda', 

        'value' => $directTeam, 

        'compare' => '=' 

       ), 

       array(

        'key' => '_live_echipa_oaspete', 

        'value' => $teamName, 

        'compare' => '=' 

       ) 

      ) 

     ); 

    } 

    else 

    { 

     $args = array(

      'post_type' => 'matches', 

      'post_status' => 'publish', 

      'posts_per_page' => 10, 

      'meta_query' => array(

       'relation' => 'OR', 

       array(

        'key' => '_live_echipa_gazda', 

        'value' => $teamName, 

        'compare' => '=' 

       ), 

       array(

        'key' => '_live_echipa_oaspete', 

        'value' => $teamName, 

        'compare' => '=' 

       ), 

      ) 

     ); 

    } 









    $query = new WP_Query($args); 



    $matches = $query->posts; 



    return $matches; 

} 



function matchStatusGazde($matchID) 

{ 

    $statusIstoric = get_post_meta($matchID, '_live_status_meci_gazde', true); 

    $result = new stdClass(); 
    switch ($statusIstoric) 
    { 
     case 'v': 
      $icon = 'smileyface1.png'; 
      break; 
     case 'e': 
      $icon = 'smileyface3.png'; 
      break; 
     case 'i': 
      $icon = 'smileyface2.png'; 
     default: 
      break; 
    } 

    if ($icon) 
    { 
     $pathImg = get_stylesheet_directory_uri() . "/library/images/$icon"; 
     $image = "<img src='$pathImg' border='0'/>"; 

    } 


    $result->image = $image; 



    return $result; 

} 





function matchStatusOaspeti($matchID) 

{ 
    $statusIstoric = get_post_meta($matchID, '_live_status_meci_oaspeti', true); 

    $result = new stdClass(); 

    switch ($statusIstoric) 
    { 
     case 'v': 
      $icon = 'smileyface1.png'; 
      break; 
     case 'e': 
      $icon = 'smileyface3.png'; 
      break; 
     case 'i': 
      $icon = 'smileyface2.png'; 
     default: 
      break; 

    } 
    if ($icon) 
    { 
     $pathImg = get_stylesheet_directory_uri() . "/library/images/$icon"; 
     $image = "<img src='$pathImg' border='0'/>"; 
    } 

    $result->image = $image; 

    return $result; 

} 

回答

0

有未由於未定義的病例被定義的方式而定義的變量。

需要修正matchStatusGazde()matchStatusOaspeti()。下面是一種方法的例子。

function matchStatusOaspeti($matchID) 
{ 
    $statusIstoric = get_post_meta($matchID, '_live_status_meci_oaspeti', true); 
    $result = new stdClass(); 
    switch ($statusIstoric) 
    { 
     case 'v': 
      $icon = 'smileyface1.png'; 
      break; 
     case 'e': 
      $icon = 'smileyface3.png'; 
      break; 
     case 'i': 
      $icon = 'smileyface2.png'; 
     default: 
      // define $icon as false 
      $icon = false; 
      break; 
    } 
    // if a case above is not evaluated and there is no default then $icon would not be set and this returns a notice 
    if ($icon) 
    { 
     $pathImg = get_stylesheet_directory_uri() . "/library/images/$icon"; 
     $image = "<img src='$pathImg' border='0'/>"; 
    } 
    else 
    { 
     // if $image is only defined if $icon is set then $image would be undefined and this returns a notice 
     $image = false; // or '' or 0 depending on how the result is used 
    } 
    $result->image = $image; 
    return $result; 
} 

最可能的原因不是PHP版本的變化,而是php.ini中的display_errors設置。也就是說,在舊服務器上,display_errors設置可能不包括通知,而在新服務器上它卻包含通知。

對於生產服務器,建議您使用

E_ALL & ~E_DEPRECATED 

在發展,你應該使用

E_ALL | E_STRICT 

這樣就可以追蹤到這些類型的通知(如不確定的變量)和固定。

您可以在php.ini文件中或者在使用ini_set()

+0

感謝特里斯坦你的代碼更改值,不幸的是,問題是,我不能追查錯誤。在wordpress中,你可以通過添加define('WP_DEBUG',false)來隱藏所有的通知。在wp-config.php這裏的問題是,代碼不生成$ image變量,我正在尋找解決方案,不隱藏通知:) – AXLwarrior

+0

@AXLwarrior:那麼你應該問這個問題。 Tristan的文章對你提出的問題是一個完美的答案。 – lxg

+0

我編輯過,以顯示如何解決未定義的變量 – Tristan