Cannot use object of type stdClass as array

Hi all,

I'm catching the delete relationship event and running a check from another plugin with the following:


register_elgg_event_handler('delete', 'my_course', 'LiHaiCredits_pay');



my function is the following:
function LiHaiCredits_pay($event, $object_type, $object){
$user = get_entity($object['guid_one']); // (line 134)
$course = get_entity($object['guid_two']);
I'm getting the following fatal error Cannot use object of type stdClass as array ... on line 134.
I'm not really sure why. I have an identical function that catches the create relationship event and uses the exact same coding:
function LiHaiCredits_reserve($event, $object_type, $object){
$user = get_entity($object['guid_one']);
$course = get_entity($object['guid_two']);
without any problems.
a var_dump($object) produces the following data:
object(stdClass)#199 (5) { ["id"]=> string(4) "1378" ["guid_one"]=> string(1) "2" ["relationship"]=> string(9) "my_course" ["guid_two"]=> string(4) "1750" ["time_created"]=> string(10) "1332518468" }

Does anyone know why it might let me do it for the create relationship event but not the delete relationship?
I did think it was because it was looking for something after it had been deleted, but docs says it will run event catchers before the relationship is deleted not after, so it should still be there.
Any help is appreciated.


  • problem solved...

    it works when I use $object->guid_one instead of $object['guid_one'].

    Strange that for creating a relationship it works in array format but for deleting it doesn't.