Invalid argument supplied for foreach() in web service API - php

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?

Related

How to solve the error: call_user_func() expects parameter 1 to be a valid callback, second array member is not a valid method

This project worked for sometime and i haven't done any changes to it. One day, i was just curious and decided to check on it but now it doesn't work anymore.
Notice: Undefined index: type in
/Applications/XAMPP/xamppfiles/htdocs/icilending/web/actions.php on
line 5
Warning: call_user_func() expects parameter 1 to be a valid callback,
second array member is not a valid method in
/Applications/XAMPP/xamppfiles/htdocs/icilending/web/actions.php on
line 5
Code:
require_once("../src/inc/init.php");
call_user_func([new Controller, $_POST['type']]);

Warning: Invalid argument supplied for foreach() in classipress

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

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

uploading large GIFS with Kusaba

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

Categories