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

Changes to variables by includes not taken into account #10869

Open
micaherne opened this issue Apr 12, 2024 · 1 comment
Open

Changes to variables by includes not taken into account #10869

micaherne opened this issue Apr 12, 2024 · 1 comment

Comments

@micaherne
Copy link

Bug report

Where a variable is set and there is a possibility for an include to change it, it doesn't seem to be taken into account. For example in the code snippet provided, if the included file contains this:

<?php

$items = ['some', 'data'];

then the $items variable is not null but PHPStan detects it as always null.

Code snippet that reproduces the problem

https://phpstan.org/r/6f80e0db-de7c-4c1d-adba-afc10d2f34a6

Expected output

PHPStan shouldn't assume that the variable is unchanged after the include.

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

No response

@ondrejmirtes
Copy link
Member

Modern code shouldn't use include so that's why PHPStan currently does not understand this. You can override the variable types with @var: https://phpstan.org/r/20f0cb75-3dba-47ea-9e5a-ed299c05b271

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

No branches or pull requests

2 participants