1

I don't know how many of you are familiar with the parse.com platform, but I am utilizing the third party php library that is linked on their website and I am running into a couple problems.

Link: Parse.com PHP Library

I am trying to query my db but it keeps returning Notice: Trying to get property of non-object. From what I can see my code is correct but the error originates from one of the files included in the library.

Here is my code thus far:

function storeInParseDB ($message, $unit) {

    $parse = new parseQuery($class = 'PushNotifications');
    $parse->whereEqualTo('unit', $unit);
    $result = $parse->find();

    echo "RESULT: ";
    print_r($result);
}

Code that is throwing the error:

private function checkResponse($response,$responseCode,$expectedCode){
        //TODO: Need to also check for response for a correct result from parse.com
        if($responseCode != $expectedCode){
            $error = json_decode($response);
            $this->throwError($error->error,$error->code);
        }
        else{
            //check for empty return
            if($response == '{}'){
                return true;
            }
            else{
                return json_decode($response);
            }
        }
    }

Any help would be greatly appreciated.

6
  • Can you point out the erroneous line? Commented Jan 19, 2013 at 23:48
  • line 176 which is: $this->throwError($error->error,$error->code); I thought I read something somewhere stating it had to do with the json_decode function... Commented Jan 19, 2013 at 23:52
  • github.com/apotropaic/parse.com-php-library/issues/30 Commented Jan 19, 2013 at 23:54
  • It seems this error will be thrown if json_decode returns null. Commented Jan 19, 2013 at 23:58
  • Which it is because I have added a print_r($response) just above it, and it is empty. So I don't know if it has to do with XAMPP or what.... Commented Jan 20, 2013 at 0:02

1 Answer 1

1

I'm running the following code after cloning https://github.com/apotropaic/parse.com-php-library.git - created a parseConfig.php file with appid, restkey and masterkey as decribed in the readme.

I created a new Class in the Parse Data Browser with a single column "unit" of type string and added one row to it, unit = test.

<?php

include 'parse.com-php-library/parse.php';

function storeInParseDB ($message, $unit) {
        $parse = new parseQuery('PushNotifications');
        $parse->whereEqualTo('unit', $unit);
        $result = $parse->find();

        echo "RESULT: ";
        print_r($result);
}

storeInParseDB('hi', 'test');

As you can see I get the desired output back, make sure you have setup your parseConfig.php file correctly.

RESULT: stdClass Object
(
    [results] => Array
        (
            [0] => stdClass Object
                (
                    [unit] => test
                    [createdAt] => 2013-01-21T14:57:26.613Z
                    [updatedAt] => 2013-01-21T14:57:26.613Z
                    [objectId] => 0uiYuJcRYY
                )

        )

)
Sign up to request clarification or add additional context in comments.

1 Comment

Works fine using MAMP, but for some reason, on a Windows Machine using XAMPP the json_decode function screws it up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.