Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 368
user3450716 Avatar asked Mar 22 '14 20:03

user3450716


3 Answers

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;
}
like image 91
Abhik Chakraborty Avatar answered Oct 17 '22 21:10

Abhik Chakraborty


@user3450716, the only thing you need to do, as Abhik Chakraborty said, is to delete the $_POST from your function rt_check_sidebar parameters and leave the function with no parameters, like this:

your line 540:

function rt_check_sidebar_array($_POST){

change it to:

function rt_check_sidebar_array(){
like image 35
Sebastian Lucaci Avatar answered Oct 17 '22 19:10

Sebastian Lucaci


@user3450716. You can't change superglobal variables too, so you can't use unset($_POST[$key])

function rt_check_sidebar_array(){
    $post = $_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;
            }               
        }
    }

    // idk why you wrote this,
    // because $newPost variable isn't used in the code above and below
    $newPost == $newPost ? $newPost : $post;

    return $post;
}
like image 2
Nick Kravchenko Avatar answered Oct 17 '22 19:10

Nick Kravchenko