Closed cubycode closed 6 years ago
Try printing your error, it will give you exact line number in which foreach is throwing error. And then you can find out what argument you are passing which is invalid, several reasons can be associated with invalid argument, eg. not an array, empty, null etc.
Btw, here are the lines numbers:
Warning: Invalid argument supplied for foreach() in src/Parse/ParseObject.php on line 634
Warning: Invalid argument supplied for foreach() in src/Parse/ParseObject.php on line 670
Warning: Invalid argument supplied for foreach() in src/Parse/ParseObject.php on line 634
Warning: Invalid argument supplied for foreach() in src/Parse/ParseObject.php on line 670
So are u calling "_mergeAfterFetch" of parse SDK, from ur php file?
Try putting try catch on the function .. in ur php file ( and not SDK file ) and in catch u can print_r error
try
{
ur code
}
catch (Exception $e)
{
print_r($e);
}
I already did that for my query in my index.php file, but it doesn't print any error, just those warnings relative to ParseObject, so not my code but the Parse PHP SDK code...
So are u calling "_mergeAfterFetch" of parse SDK, from ur php file?
No, I never used that command in my code.
You will have to find out which method you are calling, which is giving u error!
This is what I call in the first block, as soon as the page gets loaded:
// Get parse Object by its objectID
$eObjID = $_GET['eObjID'];
try {
$eObj = new ParseObject("Events", $eObjID);
$eObj->fetch();
// Get title
$title = $eObj->get('title');
echo $title;
// error
} catch (ParseException $e){ echo $e->getMessage(); }
This code was working fine until 2 hours ago, it's all I know, because it doesn't print any error in the catch function.
// Get parse Object by its objectID
$eObjID = $_GET['eObjID'];
try {
$query = new ParseQuery("Events");
$query->equalTo("objectId",$eObjID);
$eObj = $query->first();
// Get title
$title = $eObj->get('title');
echo $title;
// error
} catch (ParseException $e){ echo $e->getMessage(); }
Can u try using this? Make sure $_GET['eObjID'] has an objectId, if this works for u, I will tell u the bugs.
I did, and it actually works, so do you mean that the fetch()
function doesn't work anymore on Parse PHP SDK?
$eObj = new ParseObject("Events", $eObjID);
$eObj->fetch();
UPDATE: It stopped working again:
Warning: Invalid argument supplied for foreach() in /home/fvima186/public_html/events/src/Parse/ParseQuery.php on line 603
Fatal error: Call to a member function get() on array in /home/fvima186/public_html/events/event-details.php on line 46
Here's my code:
// Get parse Object by its objectID
$eObjID = $_GET['eObjID'];
try {
$query = new ParseQuery("Events");
$query->equalTo("objectId", $eObjID);
$eObj = $query->first();
// Get title
$title = $eObj->get('title');
// Get description
$description = $eObj->get('description');
echo '
<title>' .$title. '</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="' .$description. '">
';
// error
} catch (ParseException $e){ echo $e->getMessage(); }
line 46 is this one:
$title = $eObj->get('title');
Looks like ur $eObj is empty, try printing it using print_r($eObj), if empty it will print empty array[], that means either u r providing wrong objectId or name of model 'Events' is wrong!
I could successfully use fetch(); since 2 hours ago, it's been 2 months I'm using it :) Anyway, my site stopped working even with the ParseQuery you posted above, I'm also launching a query in index.php, and it throws the same warning, so now even the ParseQuery is not working fine...
My $eObj is not empty, it's a $_GET variable:
$eObjID = $_GET['eObjID'];
print_r($eObjID);
// prints: iUqVPNtvoo
Talking about $eObj and not $eObjID.. :)
yep, it successfully gets printed out (the $eObj pare object) :)
Parse\ParseObject Object ( [serverData:protected] => Array ( [title] => LAST: Wedding Event in NYC [description] => lorem ipse dolor quantum lorem ipse dolor quantum lorem ipse dolor quantum lorem ipse dolor quan etc...
so, it seems the issue comes out when i add this line:
$title = $eObj->get('title');
if i comment it out, and i print $eObj
, it works smoothly even with the fetch()
function...
I confirm this is an issue with the 1.3.0 version of this SDK because I've just uploaded an older version of the src/Parse folder on my server and my website is working perfectly.
I see, I m still using, 1.2.0
actually, i’ve discovered that it may be a back4app server issue, because i’ve hosted Parse Server on Heroku and it works smoothly, so i’m gonna close this issue since it seems that Parse php sdk is fine. thanks for your help anyway!
Glad to see you've managed to resolve it @fvimagination . For future reference first
will return an empty array if no object is found, rather than the expected object (or null). Be sure to sanity check what you're getting back from a query before you assume it's a valid object, especially from first
. It's likely that the eObjID you were expecting to match was not actually valid in one case or another.
It simply was a back4app strange server issue, I've contacted those guys and they fixed it :)
Issue Description
Hi there, I'm getting this issue while loading my websites with Parse PHP SDK today, it's been an hour so far. I also get this error about ParseQuery.php: Warning: Invalid argument supplied for foreach() in src/Parse/ParseQuery.php
Steps to reproduce
Just try this website: http://fvimagination.com/events/index.php, it seems there's an issue on ParseObject.php
Environment Details