-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add param out for propertyAccessor #386
Conversation
@@ -15,7 +15,7 @@ | |||
"require": { | |||
"php": "^7.2 || ^8.0", | |||
"ext-simplexml": "*", | |||
"phpstan/phpstan": "^1.10.36" | |||
"phpstan/phpstan": "^1.10.62" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For conditional phpstan-param-out
Thank you. |
/** | ||
* @phpstan-template T of object|array<mixed> | ||
* @phpstan-param T &$objectOrArray | ||
* @phpstan-param-out ($objectOrArray is object ? T : array<mixed>) $objectOrArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, just for my understanding - this could be simply @phpstan-param-out T $objectOrArray
as well, right?
I had a local stub with something like that and got an error when updating because of this PR -> could remove my local stub -> thx! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phpstan-template T of object|array<mixed>
@phpstan-param T &$objectOrArray
@phpstan-param-out T $objectOrArray
doesn't give the same beahvior
It fails
$array = [1 => 'ea'];
$propertyAccessor->setValue($array, 'foo', 'bar');
assertType('array', $array);
You'll get array{1: 'ea'}
instead, which is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK, makes sense. Thx!
When setting value to an object the object type does not change.
When setting value to an object, the array values change. But at least we know it's an array and not
array|object
.