Skip to content

Conversation

@guilliamxavier
Copy link
Contributor

@guilliamxavier guilliamxavier commented Dec 5, 2019

Fixes #46
Closes #105

@msftclas
Copy link

msftclas commented Dec 5, 2019

CLA assistant check
All CLA requirements met.

@guilliamxavier guilliamxavier marked this pull request as ready for review December 5, 2019 16:14
@guilliamxavier
Copy link
Contributor Author

(I have added 2 extra commits I think make the code better, but they're optional, feel free to discard them)

@MIchaelMainer
Copy link
Collaborator

Thank you @guilliamxavier . I'm going to run this tomorrow. I'll be bumping the version to 2.0.0 as it is possible that people have taken a dependency on the old behavior.

@guilliamxavier
Copy link
Contributor Author

Thank you for responding. As concerns a hypothetical dependency on the buggy behavior... given for example

$query = http_build_query(['$filter' => $filter, '$orderby' => $orderby]);
$userGrabber = $graph->createCollectionRequest('GET', "/users?$query")
                     ->setReturnType(Model\User::class)
                     ->setPageSize(100);
$users = $userGrabber->getPage();

I admit that (although very unlikely) there is indeed a slight possibility that someone might have written some "fragile" code like

// this code assumes that $users cannot be empty:
if (is_array($users)) {
    /* code that must be run if the real collection was not empty (use $users) */
} else {
    /* code that must be run if the real collection was empty (don't use $users) */
}

and would need to change it (actually, to fix it), but there's a much higher probability that people have written reasonable code like

// this code trusts that $users is an array:
if (count($users) > 0) {
    /* code that must be run if the real collection was not empty (use $users) */
} else {
    /* code that must be run if the real collection was empty (don't use $users) */
}

then if got bitten by the bug (e.g. "expected array, got object"), adapted it like this:

// this code checks to be sure that $users is an array:
if (is_array($users) && count($users) > 0) {
    /* code that WILL be run if the real collection was not empty (use $users) */
} else {
    /* code that WILL be run if the real collection was empty (don't use $users) */
}

or (that's me) like that:

// Workaround for bug https://github.com/microsoftgraph/msgraph-sdk-php/issues/46
if (!is_array($users)) {
    $users = [];
}

// this code can now be confident that $users is an array:
if (count($users) > 0) {
    /* code that WILL be run if the real collection was not empty (use $users) */
} else {
    /* code that WILL be run if the real collection was empty (don't use $users) */
}

For me it would be a bit sad if people who are using version ^1.0 / 1.* would not get the bugfix (until --if ever-- they do a major version upgrade to ^2.0 / 2.*) because of an unknown [small] number of "sloppy" coders... But if you have a very strict BC policy (even for bugs), I guess that's how it is... Anyhow thank you for considering 🙂

Copy link
Collaborator

@MIchaelMainer MIchaelMainer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @guilliamxavier for your time on this. And FYI, I'm going to be updating PHP to 7.4 as well as updating the dependencies.

@MIchaelMainer MIchaelMainer merged commit 0fb3169 into microsoftgraph:dev Jan 28, 2020
@guilliamxavier guilliamxavier deleted the fix-46 branch January 29, 2020 08:11
@guilliamxavier
Copy link
Contributor Author

I see that this was released in 1.13.0 (with a bump to PHP 7.1) 🎉 Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Requesting an empty collection returns an object of the return type

3 participants