Skip to content

RequireFileExistsRule: enable __DIR__ only for bleeding edge#5879

Merged
staabm merged 1 commit into
phpstan:2.2.xfrom
staabm:bleed
Jun 15, 2026
Merged

RequireFileExistsRule: enable __DIR__ only for bleeding edge#5879
staabm merged 1 commit into
phpstan:2.2.xfrom
staabm:bleed

Conversation

@staabm

@staabm staabm commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

the rule, which was improved with #5862, did only work before when a opt-in usePathConstantsAsConstantString: true flag was used. I feel this mean only very few users had it in use.

with the mentioned PR, the rule covers more real world use-cases, because the added behaviour does not depend on the opt-in flag.

to play it save, lets enable the newly added logic only in bleeding edge for now

VincentLanglet
VincentLanglet previously approved these changes Jun 15, 2026
@VincentLanglet VincentLanglet self-requested a review June 15, 2026 13:03
@VincentLanglet

Copy link
Copy Markdown
Contributor

with the mentioned PR, the rule covers more real world use-cases, because the added behaviour does not depend on the opt-in flag.

Should it behind the same opt-in flag instead then ?

@staabm

staabm commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Should it behind the same opt-in flag instead then ?

I don't think so, because the opt in flag usePathConstantsAsConstantString is not triggered in bleeding edge.

the new behaviour from #5862 is meant to be generally available in phpstan 3.0 and should be enabled with bleeding edge to verify it works as expected

@VincentLanglet

Copy link
Copy Markdown
Contributor

Should it behind the same opt-in flag instead then ?

I don't think so, because the opt in flag usePathConstantsAsConstantString is not triggered in bleeding edge.

The new behavior consider __DIR__.'foo' as a constant, which is kinda consistent with usePathConstantsAsConstantString. It could be considered weird to have the check for DIR and not for pathConstants.

the new behaviour from #5862 is meant to be generally available in phpstan 3.0

That's the only concern I have, should it really be generally available ?

Maybe it has to be behing usePathConstantsAsConstantString + bleedingEdge and in 3.0 it will be behind usePathConstantsAsConstantString.

Looking at the doc of https://phpstan.org/config-reference#usepathconstantsasconstantstring ; it explicitely say

When set to true, the magic constants FILE and DIR are resolved to their literal file path values instead of being generalized to string. This enables rules that depend on exact path values, such as checking whether a file referenced by require actually exists.

So I understand by this doc that the #5862 behavior should be behind the flag ?

@staabm

staabm commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

if I put it behind usePathConstantsAsConstantString + bleedingEdge it will see even less users usePathConstantsAsConstantString alone already have. so it would be even less useful.

from my POV the goal of #5862 is, that RequireFileExistsRule can deliver its real value, even when usePathConstantsAsConstantString is not enabled.

at the time RequireFileExistsRule was implemented, the only way to make it work was with usePathConstantsAsConstantString enabled. IMO its a shortcoming from day 1 of this rule.

the usePathConstantsAsConstantString existed even before

@VincentLanglet VincentLanglet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see why it shouldn't also be behind usePathConstantsAsConstantString but I agree it has to be behing bleeding edge anyway

@staabm staabm merged commit c7307df into phpstan:2.2.x Jun 15, 2026
669 of 673 checks passed
@staabm staabm deleted the bleed branch June 15, 2026 13:56
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.

2 participants