I got an Error While i submit the Ad if i can not check the mandatory field in form,
The Error Is
Warning: Invalid argument supplied for foreach() in
/home/*******/public_html/wp-content/themes/classipress/includes/views-checkout.php
on line 1358
-
Warning: Invalid argument supplied for foreach() in
/home/*******/public_html/wp-content/themes/classipress/includes/views-checkout.php
on line 954
Check the code once foreach() can only accept array or object.
Note that
Provide code where you have this problem so I can help you better
foreach() can only accept the array or object
Related
Suddenly, my php log is getting flooded with this php warning:
Got error 'PHP message: PHP Warning: Invalid argument supplied for foreach() in /public_html/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-dashboard.php on line 543', referer:
The warning always keep the same but the referer could be literally any page of the site, including back and front end. I really don't have a clue whats going on.
Any ideas?
Using a solution found in Invalid argument supplied for foreach()
You can edit 'class-wc-admin-dashboard.php' and add this code in line 543 (just before the foreach):
if (is_array($data) || is_object($data))
Originally I was trying to solve this issue:
403 Error Persists After Changing File Permissions & Editing Htaccess File
Before I make too many changes to my code I would like to understand the problem.
After the suggestion of #misorude I checked the PHP error logs for the directory that the code causing the error existed in. I found the following error.
[12-Jan-2019 15:23:49 America/Chicago] PHP Warning: Invalid argument supplied for foreach() in /home/bullbusterweb/public_html/community/profile.php on line 898
I have tried the following to understand this issue.
1) I googled what invalid argument supplied for foreach() could mean and found the following result.
Invalid argument supplied for foreach()
2) Then I looked at my code to see what could be causing this.
The foreach in question was here:
'''php
foreach($Articles as $Article){
'''
The first place 'Articles is defined is
$Articles = $Ambassador->getArticles();
A few lines above the foreach() I found the following code related to the articles variable.
// var_dump($Articles);
if(isset($Articles)){
According to the php manual:
var_dump : "Dumps information about a variable" .
isset: " Determines if a variable is set and is not NULL"
I tried uncommenting the var_dump but found that it messed up the formatting of the page. So now I know why it is commented out.
I'm using PHP code to call Json API, but I'm having Issues loading.
PHP code
$response[$i]['id']=$dataFriend[$i]['id'];
$response[$i]['name']=$dataFriend[$i]['name'];
$response[$i]['id']=$id;
$response[$i]['lastMSGFrom']=$msg_from;
$response[$i]['lastMSGType']=$type;
$response[$i]['lastMSG']=$msg;
$response[$i]['lastMSGTime']=$time;
$response[$i]['lastSeen']=$dataFriend[$i]['date'];
$response[$i]['status']=$dataFriend[$i]['status'];
}
}
foreach ($response as $key => $row) {
$volume[$key] = $row['lastMSGTime'];
}
array_multisort($volume, SORT_DESC, $response);
array_unshift($response, $userData);
Error log
PHP Warning: Invalid argument supplied for foreach()
PHP Warning: array_multisort(): Argument #1 is expected to be an array or a sort flag
PHP Warning: array_unshift() expects parameter 1 to be array, null given
PHP Warning: Invalid argument supplied for foreach()
PHP Warning: array_multisort(): Argument #1 is expected to be an array or a sort flag
PHP Warning: array_unshift() expects parameter 1 to be array, null given
I would appreciate any ideas?
I got this error log few days ago
PHP Warning: Invalid argument supplied for foreach() in /home/karatm/public_html/wp-content/plugins/gantry/bugfixes.php on line 52<br>
PHP Warning: Invalid argument supplied for foreach() in /home/karatm/public_html/wp-content/plugins/gantry/bugfixes.php on line 52<br>
PHP Warning: Invalid argument supplied for foreach() in /home/karatm/public_html/wp-content/plugins/gantry/bugfixes.php on line 102<br>
This is line 52 from bugfixes.php:
foreach($sidebar_contents as $sidebar_contents_id => &$sidebar_widget_instance)
This is line 102 from bugfixes.php:
foreach ($override_sidebar as $position => &$sbw_instances)
What this error mean, how can i fix this ?
(if someone can help me, i can send him the full .php file)
Thanks
foreach ($override_sidebar as $position => &$sbw_instances)
try to remove &
try this
foreach ($override_sidebar as $position => $sbw_instances)
This doesn't always happen. I could upload the same GIF sometimes and sometimes receive back this error, it seems almost random.
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*001/*.org/www/inc/classes/board-post.class.php on line 81
Warning: Cannot modify header information - headers already sent by (output started at /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php:81) in /webroot/i/n/*/*.org/www/board.php on line 343
Warning: Cannot modify header information - headers already sent by (output started at /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php:81) in /webroot/i/n/*/*.org/www/board.php on line 347
Warning: Cannot modify header information - headers already sent by (output started at /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php:81) in /webroot/i/n/*/*.org/www/board.php on line 350
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/func/posts.php on line 249
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php on line 136
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php on line 163
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/func/fetching.php on line 27
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php on line 343
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php on line 443
Warning: Invalid argument supplied for foreach() in /webroot/i/n/*/*.org/www/inc/func/fetching.php on line 27
Warning: Cannot modify header information - headers already sent by (output started at /webroot/i/n/*/*.org/www/inc/classes/board-post.class.php:81) in /webroot/i/n/*/*.org/www/inc/func/misc.php on line 76
Somewhere you're using a variable that's not an array in a foreach statement, like:
$foo = 123;
foreach ($foo as $bar)
This throws the Invalid argument supplied for foreach() warning. Check your variables better to make sure they're arrays when they're expected to be.
The fact that this warning was thrown and output blocks headers from being sent, which causes the other Cannot modify header information warning.
If you want to cycle through the $results array, you should write
foreach ($results as $key=>$value)
rather than
foreach ($results[0] as $key=>$value)
unless $results[0] itself is an array, in which case $results would be a matrix (array of arrays).