Conversation
baywet
left a comment
There was a problem hiding this comment.
this is really close to what we need for a first iteration! I left a few comments here and there where things are missing, mostly null check. I'm confident that with a couple of fast iterations we'll be able to get an excellent definitive copy. Thanks for all the work so far!
msgraph-mail/php/src/Users/Item/InferenceClassification/Overrides/OverridesRequestBuilder.php
Show resolved
Hide resolved
msgraph-mail/php/src/Users/Item/InferenceClassification/Overrides/OverridesRequestBuilder.php
Show resolved
Hide resolved
msgraph-mail/php/src/Users/Item/InferenceClassification/Overrides/OverridesRequestBuilder.php
Outdated
Show resolved
Hide resolved
msgraph-mail/php/src/Users/Item/InferenceClassification/Overrides/OverridesRequestBuilder.php
Show resolved
Hide resolved
|
Hello @baywet, thanks for taking the time to review the PR, I have been working on the issues <?php
class SomeClass {
function someMethod(): void {
echo 'I am able to call this function.';
}
}
function someFunction(User $user): void {
$user->someMethod();
}
someFunction(null);The above code throws the error below.
But when we slightly change the function <?php
class SomeClass {
function someMethod(): void {
echo 'I am able to call this function.';
}
}
function someFunction(?User $user): void {
$user->someMethod();
}
someFunction(null);
|
|
Thanks for taking the suggestions during the review process. |
f0f7e52 to
7e9117e
Compare
Hi @baywet , I did have the checks but removed them on this commit 1e855e0. Based on the example below, I decided to remove the null checks since it only works when the parameter is optional or nullable. <?php
function getTime(DateTime $dateTime): string {
if (is_null($dateTime)) {
throw new \InvalidArgumentException('$dateTime cannot be null.');
}
return $dateTime->format('H:i:s');
}
$time = getTime(null);
// Expect InvalidArgumentException to be thrown?
// that's actually not the case. The exception is never going to be thrown
// as expected, instead PHP throws TypeError. Unless you change the code to below.
function getTime(?DateTime $dateTime): string {
if (is_null($dateTime)) {
throw new \InvalidArgumentException('$dateTime cannot be null.');
}
return $dateTime->format('H:i:s');
}
$time = getTime(null);
// Is this case the exception is going to be thrown because the Argument is nullable.Since the parameters in question are never nullable. The null check part is never going to be executed even when we pass the null as argument to the function call. NOTE: The null check on the first code above is marked by PhpStorm and phpstan as unnecessary.I hope this justifies why we don't need the null check. |
|
ok thanks for taking the time to go through that. If I understand things correctly, as long as a parameter is not defaulted to null or its type is not | null, the runtime will enforce not getting a null value. Perfect! |
That's correct. |

This PR contains