Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
478 views
in Technique[技术] by (71.8m points)

php - Fatal error: Cannot re-assign auto-global variable _POST

I can't get access to my WP (version3.4.2) admin. It says as mentioned above

Fatal error: Cannot re-assign auto-global variable _POST in /home/xxx/public_html/wp-content/themes/rtthemes16/rt-framework/classes/admin.php on line 540.

The line 540 is :

function rt_check_sidebar_array($_POST){

    if(is_array($_POST)){

        $start_unset_count = 0;

        foreach($_POST as $key => $value){
            if(stristr($key, '_sidebar_name') == TRUE && $value=="") {                  
                unset($_POST[$key]);
                $start_unset_count = 1;
            }

            if($start_unset_count>0){
                unset($_POST[$key]);
                $start_unset_count++;
            }

            if($start_unset_count==6){
                $start_unset_count = 0;
            }               
        }
    }


    $newPost == $newPost ? $newPost : $_POST;       
    return $_POST;
}

Any insights? Thanks :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since PHP 5.4, you cannot use a superglobal as the parameter to a function

$_POST is globally accessible. So you don't have to pass to your function.

http://php.net/manual/en/language.variables.superglobals.php#112184

This is how your function should look like

function rt_check_sidebar_array(){

    if(is_array($_POST)){

        $start_unset_count = 0;

        foreach($_POST as $key => $value){
            if(stristr($key, '_sidebar_name') == TRUE && $value=="") {                  
                unset($_POST[$key]);
                $start_unset_count = 1;
            }

            if($start_unset_count>0){
                unset($_POST[$key]);
                $start_unset_count++;
            }

            if($start_unset_count==6){
                $start_unset_count = 0;
            }               
        }
    }


    $newPost == $newPost ? $newPost : $_POST;       
    return $_POST;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...