Skip to content

Fix PropertyExistsTypeSpecifyingExtension for union types #4153

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
wants to merge 10 commits into
base: 2.1.x
Choose a base branch
from

Conversation

liamduckett
Copy link

closes phpstan/phpstan#13304

@staabm it'd be great to take you up on any guidance - especially because this PR is so heavily based on your changes in #4150. Thanks!

I believe my changes allow narrowing based on an array of constant strings, unless:

  1. Any of them are empty
  2. Any of them aren't native

I was trying to reason as to whether it'd make sense to try and narrow based on parts of the union (for example, if it contains an empty string, but also a non empty string?) but I think I'm out of brainpower for the day.

@liamduckett liamduckett marked this pull request as draft July 23, 2025 19:34
@liamduckett
Copy link
Author

Looks like I need to remove something from the baseline, and probably rejig my empty string check to be later down.

Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey,

thanks for the pull request. it looks mostly good already.

I see the following todos atm

  • look at the PHPStan errors of the PHP8.x builds first (the PHP7.x errors are likely reported on the wrong line, as the source code is transformed for PHP7.x compat). Usually most of the PHP7.x errors go away after you fix the PHP8 ones.
  • after you fixed all newly reported PHPStan errors, you can run make phpstan-generate-baseline to cleanup the "Ignored error pattern XXX" errors
  • run make cs-fix to fix the Lint / Coding Standard problems
  • run make locally to verify all sanity checks are green
  • some of the GitHub Action checks fail unrelated to this PR. to get an idea which, its oftentimes usefull to look at other recent PRs and see whether these report the same problems.

@liamduckett
Copy link
Author

Thanks @staabm. I think most of the failing action checks are from other PRs, as you described?

The exception to this is doctrine/orm (see action), in which I think we've found legitimate issues to report. I believe the simplest example of this is here, but they all follow this general pattern.

@staabm
Copy link
Contributor

staabm commented Jul 24, 2025

The exception to this is doctrine/orm (see action), in which I think we've found legitimate issues to report. I believe the simplest example of this is here, but they all follow this general pattern.

These look good to me

@liamduckett
Copy link
Author

Thanks again!

@VincentLanglet
Copy link
Contributor

You might want to mark this PR as ready @liamduckett ?

@liamduckett liamduckett marked this pull request as ready for review July 25, 2025 15:50
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

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.

property_exists cannot narrow type when property is a union
4 participants