Skip to content
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

Merged
merged 2 commits into from
Mar 16, 2024

Conversation

VincentLanglet
Copy link
Contributor

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.

@@ -15,7 +15,7 @@
"require": {
"php": "^7.2 || ^8.0",
"ext-simplexml": "*",
"phpstan/phpstan": "^1.10.36"
"phpstan/phpstan": "^1.10.62"
Copy link
Contributor Author

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

@ondrejmirtes ondrejmirtes merged commit a32bc86 into phpstan:1.3.x Mar 16, 2024
31 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

/**
* @phpstan-template T of object|array<mixed>
* @phpstan-param T &$objectOrArray
* @phpstan-param-out ($objectOrArray is object ? T : array<mixed>) $objectOrArray
Copy link
Contributor

@herndlm herndlm Mar 18, 2024

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! :)

Copy link
Contributor Author

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.

Copy link
Contributor

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!

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.

3 participants