0

Here is the $object that Microsoft is returning to me:

object(Microsoft\Graph\Model\Event)#56 (1) {
  ["_propDict":protected]=>
  array(2) {
    ["@odata.context"]=>
    string(245) "https://graph.microsoft.com/v1.0/$metadata#users('email%40outlook.com')/calendars('AAAAAAAAAAAAAAAAAAAAAAAA')/calendarView"
    ["value"]=>
    array(0) {
    }
  }
}

I'm trying to check if value's array contains nothing in it. I'm having trouble accessing "value" as it just says array. Here is what I've already tried doing:

$object->array;

$object->array();

$object[0];

foreach ($object as $key) {
    var_dump($key);
}

None of those work.


I'm trying to do something like this:

if(empty($object->array['value'])) {
    echo 'value is empty';
}
Timmy Balk
  • 238
  • 3
  • 14
  • `_propDict` is protected. Which means short of reflection, it's not accessible outside of the class. – ArtisticPhoenix Nov 13 '18 at 17:46
  • You won't be able to access a protected object property directly - does the class offer any getter methods? – iainn Nov 13 '18 at 17:46
  • Thank you guys. So the problem is that Microsoft does provide a way to get those protected properties, for example, `$object->getSubject()`, **BUT** `$object->getValue()` is not valid. Thanks everyone though! – Timmy Balk Nov 13 '18 at 17:51

1 Answers1

0

Entity.getProperties() function could be utilized for that purpose which returns the list of properties. Entity is a base class for Event entity.

The following example demonstrates how to determine whether entity contains property using array_key_exists function:

$requestUrl = "https://graph.microsoft.com/v1.0/drives/$targetDriveId";
$drive = $this->client->createRequest("GET", $requestUrl)
     ->setReturnType(Model\Drive::class)
     ->execute();

$properties = $drive->getProperties();  //get all properties
if (array_key_exists('id', $properties)) { //verify for id property
    print $properties["id"];
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193