-
Notifications
You must be signed in to change notification settings - Fork 152
Closed
Labels
type:questionAn issue that's a questionAn issue that's a question
Description
Issue Summary
When using the Microsoft Graph PHP SDK to retrieve items from a OneDrive directory, the DriveItemCollectionResponse and its nested DriveItem objects expose properties in the print_r() output. However, these properties cannot be accessed programmatically, making it impossible to extract data like name, createdBy, and other fields.
Steps to Reproduce
-
Query OneDrive items using the SDK:
$response = $graphClient->me()->drive()->items()->get(); $items = $response->getValue(); // Attempt to access properties foreach ($items as $item) { $name = $item->name; // Property does not exist or is inaccessible $createdBy = $item->createdBy; // Same issue }
-
Inspect the object using
print_r($response):- It shows that properties such as
nameandcreatedByare present in the object structure.
- It shows that properties such as
-
Try accessing these properties directly:
$name = $item->getBackingStore()->get('name'); // Produces inconsistent results or null
-
Attempt to convert the object to JSON or an array:
function objectToArray($object) { if (is_object($object)) { $object = get_object_vars($object); } if (is_array($object)) { return array_map('objectToArray', $object); } return $object; } $data = objectToArray($response); // Results in null values
Expected Behavior
At a minimum, properties like name, createdBy, id, etc., should be accessible programmatically from the DriveItem objects within the DriveItemCollectionResponse.
Actual Behavior
DriveItemproperties cannot be accessed programmatically even though they appear in the object structure when printed usingprint_r().- Converting the object to an array or JSON results in
nullvalues for most properties.
Workarounds Attempted
- Direct Access: Accessing properties like
$item->namedirectly results in an error. - Using Backing Store: The
getBackingStore()method does not reliably return property values. - Recursive Conversion: Converting the response to an array using custom functions results in
nullfor properties.
Proposed Solution
- Ensure all properties are accessible programmatically from
DriveItemobjects. - Add a built-in method to convert objects to arrays or JSON for easier integration with AJAX-based frontend applications.
- Provide documentation with examples on how to access and use properties programmatically.
Environment
- PHP Version: 8.4.2
- SDK Version: 2.23
Additional Context
- This issue significantly limits the usability of the SDK for modern applications.
- Being unable to access properties programmatically or convert the response to JSON prevents integration with frontend frameworks like React.
- If there is a specific intended way to access these properties, it should be explicitly documented.
Metadata
Metadata
Assignees
Labels
type:questionAn issue that's a questionAn issue that's a question