Woocommerce PHP Warning for class-wc-admin-dashboard.php - php

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

Related

Invalid argument supplied for foreach() Can This Be Caused By A 403 Error?

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.

MySQL table issue with CodeIgniter

This page was previously displaying properly. I don't see anything wrong with the specified line number in this error message. I just did a few edits on some code snippets based on what I saw in different tutorials online.
I went back through each revision I made but I still don't see anything that could have affected this function/part.
A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 0
Filename: client/view_job.php
Line Number: 75
Here's what I have on line 75:
Edit
This was perfectly displayed before. I don't know where the new issue came from.
#hsuk, I realized your point and I could actually solve it by changing
$row['job_id']
to simply
<?= $id?>
and it worked..

PHP Warning: Invalid argument supplied for foreach() - gantry plugin

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)

How to check that an XML file is good before running simplexml_load_file()

I use PHP's simplexml_load_file() function to call an API that returns changed results based on a Timestamp that I send.
So the API will return only results that have changed since my Timestamp. The problem I am having is if the timestamp is too soon and there are no results for the API to return, then it does not return a proper XML file, instead it will just return a blank page.
This is causing all sorts of problems with simplexml_load_file
Here is a simple test I can run...
$xml = 'http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1';
$xmlObj = new SimpleXMLElement($xml, NULL, TRUE);
This results in...
Warning: SimpleXMLElement::__construct(): http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1:1: parser error : Document is empty in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): ^ in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1:1: parser error : Start tag expected, '<' not found in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Warning: SimpleXMLElement::__construct(): ^ in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php:9 Stack trace: #0 E:\Server\htdocs\labs\freelance\dogAPI\testorg.php(9): SimpleXMLElement->__construct('http://api.resc...', 0, true) #1 {main} thrown in E:\Server\htdocs\labs\freelance\dogAPI\testorg.php on line 9
Now if I pass the API a Timestamp that is further back where there are results, then it will return a perfect XML document.
I am looking for a way to possibly prevent this nasty error from happening somehow?
simplexml_load_file:
Use libxml_use_internal_errors() to suppress all XML errors, and libxml_get_errors() to iterate over them afterwards.
Returns an object of class SimpleXMLElement with properties containing the data held within the XML document, or FALSE on failure.
So suppress the errors and check for FALSE to detect when the query didn't go as expected.
$xml = #simplexml_load_file('http://api.rescuegroups.org/rest/?key=CZivWWGD&type=orgs&limit=300&updatedAfter=1361941202&startPage=1');
if(false !== $xml)
{
// Do anything with xml
}
If there an errors # hide it and return false

Why am I getting *uninitialized* warning when I call a function in php?

PHP 1. {main}() /Users/aaron/NetBeansProjects/PhpProject2/CssToSQL.php:0
PHP 2. GetContentRules($contentRules = *uninitialized*) /Users/aaron/NetBeansProjects/PhpProject2/CssToSQL.php:134
Line 134: $contentRuleList = GetContentRules($configSections['vips']);
function GetContentRules($contentRules) { ... }
$configSections['vips'] contains like 1114 lines
My function works as expected, but I'm trying to figure out why this error is thrown?
TIA!
Error != warning. A warning is simply an indication of something you SHOULD fix, but don't HAVE to. If it was an error, your script would bomb out at the point the error occured. Given the error message you're sort of hinting at in the question title, your $configSections['vips'] is not defined. Either $configSections itself isn't, or there's no ['vips'] key in the array.

Categories