Fatal error: Cannot re-assign auto-global variable _POST
Solution 1
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;
}
Solution 2
@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(){
Solution 3
@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;
}
user3450716
Updated on July 20, 2020Comments
-
user3450716 almost 4 years
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 :)
-
user3450716 about 10 yearsCan you be more precise (bc the link suggests i rename the variable $)
-
Abhik Chakraborty about 10 yearsif you rename your function param name then you can access $_POST data via that param name, the best thing would be to have no param at all in
function rt_check_sidebar_array($_POST){
and should be asfunction rt_check_sidebar_array(){
since you can access $_POST inside the function directly for any operation and this is true for any super globals like $_FILES, $_GET etc. -
user3450716 about 10 yearsstill the same line; 540
-
user3450716 about 10 yearsCheck sidebar array # 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; }
-
Abhik Chakraborty about 10 yearsno u have not removed the $_POST in function param
function rt_check_sidebar_array($_POST)
it should be justfunction rt_check_sidebar_array()
and when u call this function just call it without any param. -
user3450716 about 10 yearstheres the new one # # Check sidebar array # function rt_check_sidebar_array($_POST){ if(is_array()){ $start_unset_count = 0; foreach( as $key => $value){ if(stristr($key, '_sidebar_name') == TRUE && $value=="") { unset([$key]); $start_unset_count = 1; } if($start_unset_count>0){ unset([$key]); $start_unset_count++; } if($start_unset_count==6){ $start_unset_count = 0; } } } $newPost == $newPost ? $newPost : ; return ; }
-
Abhik Chakraborty about 10 yearsin the new one also u have
function rt_check_sidebar_array($_POST)
.. please remove $_POST from the function parameter -
user3450716 about 10 yearsCheck sidebar array # function rt_check_sidebar_array(){ if(is_array()){ $start_unset_count = 0; foreach( as $key => $value){ if(stristr($key, '_sidebar_name') == TRUE && $value=="") { unset([$key]); $start_unset_count = 1; } if($start_unset_count>0){ unset([$key]); $start_unset_count++; } if($start_unset_count==6){ $start_unset_count = 0; } } } $newPost == $newPost ? $newPost : ; return ; } #
-
Abhik Chakraborty about 10 yearsu are doing wrong again check my updated answer and I would suggest to learn more on PHP functions and arguments.
-
user3450716 about 10 yearsif u could send me the sentence i should use that would b very much appreciated.. im trying to fix things, every one is not as pro as u ..thanks
-
Abhik Chakraborty about 10 yearssentence ?? did not get what u mean.
-
JayJay123 over 7 yearsWorked like a charm in fixing the install of MyITCRM.