Skip to content

array_replace change type of array #12828

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

Open
momala454 opened this issue Apr 3, 2025 · 2 comments
Open

array_replace change type of array #12828

momala454 opened this issue Apr 3, 2025 · 2 comments

Comments

@momala454
Copy link

Bug report

When using array_replace on an existing array with known keys, now the existing keys are only "possible"

Code snippet that reproduces the problem

https://phpstan.org/r/70b1e175-a50d-4521-b4ce-2ffa2aac82d5

Expected output

array{abc: 'def', hello: 'country'}

Actual output

non-empty-array<'abc'|'hello', 'country'|'def'|'world'>

Did PHPStan help you today? Did it make you happy in any way?

No response

@herndlm
Copy link
Contributor

herndlm commented Apr 4, 2025

Looks like https://github.com/phpstan/phpstan-src/blob/f2f2ddf44425cc58b5b1537ddce7cd06a9bba074/src/Type/Php/ArrayReplaceFunctionReturnTypeExtension.php does not handle constant arrays properly

It uses all input arg arrays without actually doing a replace. Looks like it would need to be rewritten or heavily adapted.

@VincentLanglet
Copy link
Contributor

@herndlm I tried to rework the extension based on the ArrayMerge one, if you want to take a look
phpstan/phpstan-src#3958

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

No branches or pull requests

3 participants