Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Error generated by BetterNotifications when trying to send private message

Vanilla 2.1
BetterNotifications 2.0.0

With debug on in config.php, when hitting Send Message to reply to a private message, I get the following:

Fatal error: Cannot use object of type stdClass as array in /home5/nilaedu/public_html/onlinecampus/plugins/BetterNotifications/class.betternotifications.plugin.php on line 48

Any suggestions welcome.

Comments

  • DoyceTDoyceT ✭✭✭

    Update: The reply is ACTUALLY posting. It just don't look like it is until I refresh the page, so I end up replying with the same post a half-dozen times. :/

  • Either cast the object to array before access or access the member directly instead.

    Adding the following line to line 47 of class.betternotifications.plugin.php should quash that error:

    $Activity = (array)$Activity;
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • DoyceTDoyceT ✭✭✭

    Will try that asap.

  • DoyceTDoyceT ✭✭✭

    Worked perfectly. Thanks!

  • Sorry it took me so long to get to this... ironically perhaps I can get some help here. I don't do a lot of PHP work, and it seems to me like explicitly casting $Activity to an array will then render the following check redundant:

    if ( is_array($Activity) ) {
       // Access by key
       $Activity['ActivityType']
    } else {
       // Access by property
       $Activity->ActivityType
    }
    

    Are you saying if I do an explicit cast to an array I can just drop the if/else and treat it as an array at all times? If so I will update the plugin.

    Also I'm confused as to why is_array is generating a fatal error. Isn't the whole point of the function to check if the provided object is an array?

  • peregrineperegrine MVP
    edited December 2014

    haven't looked at plugin - but you could do something like this

    if $Activity can be an object or an array.

     if ( (array) $Activity !== $Activity ) {   
     // Access by property   
     $x = $Activity->ActivityType;
    } else {
     // Access by key
    $x = $Activity['ActivityType'];
    }
    

    after looking at code why not change to

     $BookmarkComment = ($Activity->ActivityType == 'Comment' || $Activity->ActivityType == 'BookmarkComment');
    
    
    preg_match( "/comment\/([0-9]+)/", $Activity->Route, $RouteMatches );
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • BleistivtBleistivt Moderator
    edited December 2014

    or just use val('ActivityType', $Activity)

  • Thanks guys, @Bleistivt‌ that val() function seems to have done the trick. I take it this is a global function in Vanilla?

  • peregrineperegrine MVP
    edited December 2014

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.