Forum

Thread tagged as: Error, Api, Comments

ErrorException thrown when posting a comment

When posting a comment on a perch blog, we were receiving the following error:

ErrorException: Trying to get property of non-object in /Library/WebServer/Documents/dsear/public_html/perch/core/lib/api/PerchAPI_Base.class.php on line 19

This is on Perch 2.8.2 with the latest Blog app.

The comment was saving okay, but the error was thrown regardless. I did some digging and found it was due to Perch's logging.

To fix the error I modified the aforementioned class:

Before:

public function log_resources($resourceIDs=false)
{
    PerchUtil::debug('Logging resources for '.$this->api->app_id); // $this->api was false, so this was failing.

    if ($resourceIDs===false) {
        $Resources = new PerchResources();
        $resourceIDs = $Resources->get_logged_ids();    
    }

    if (PerchUtil::count($resourceIDs) && $this->api) {
        $app_id = $this->api->app_id;

        // ...

After:

public function log_resources($resourceIDs=false)
{
    if ($resourceIDs===false) {
        $Resources = new PerchResources();
        $resourceIDs = $Resources->get_logged_ids();    
    }

    if (PerchUtil::count($resourceIDs) && $this->api) {
        PerchUtil::debug('Logging resources for '.$this->api->app_id); // moved this line inside the conditional

        $app_id = $this->api->app_id;

        // ...

Unfortunately it was our front-end dev who found the bug, so I'm not able to say 100% what part of the template etc. caused it. I can post the full template code if necessary, but I think this fix suffices unless you want to dig further.

Cheers,

--Kieran

(Bug report mirrored in this gist: )

Kieran Patel

Kieran Patel 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I thought this had been fixed in Perch 2.8.3 - have you tried that?