douhan1992 2015-11-07 21:19 采纳率: 100%
浏览 46
已采纳

从php 5.3升级到5.4.33后的wordpress主题错误

I just switched servers for a bunch of wordpress hosted websites. On the old server we had php version 5.3, on the new one we got 5.4.33. The problem is that we're getting a lot of errors after this change and some of errors are pretty hard (for me) to solve. Have a look at the code below please :)

These are the errors that I get:

  1. Notice: Undefined variable: icon in /wp-content/themes/livescore/library/functions-single-match.php on line 138

  2. Notice: Undefined variable: image in /wp-content/themes/livescore/library/functions-single-match.php on line 145

  3. Notice: Undefined variable: icon in /wp-content/themes/livescore/library/functions-single-match.php on line 179

  4. Notice: Undefined variable: image in /wp-content/themes/livescore/library/functions-single-match.php on line 184

And this is functions-single-match.php below:

<?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;

}
  • 写回答

1条回答 默认 最新

  • douliandan7340 2015-11-07 21:26
    关注

    There are undefined variables due to the way in which unresolved cases are defined.

    Both matchStatusGazde() and matchStatusOaspeti() need to be fixed. Below is an example of one way to do that.

    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;
    }
    

    The most likely cause is not the change of PHP version but the display_errors setting in the php.ini. Ie on the old server the display_errors setting probably didn't include notices, while on the new server it does.

    For a production server it is recommended that you use

    E_ALL & ~E_DEPRECATED
    

    In development you should use

    E_ALL | E_STRICT
    

    So that you can track down these kinds of notices (such as undefined variables) and fix.

    You can change the value in the php.ini file or in your code using ini_set()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号