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

Bleeding edge: stricter ++/-- operator check #3255

Merged

Conversation

schlndh
Copy link
Contributor

@schlndh schlndh commented Jul 20, 2024

The goal of this PR was to check mixed in ++/--, but while I was at it I also fixed several other cases which were not previously reported (pretty much the same as the binary/unary operator PRs).

Current behavior: https://phpstan.org/r/974fc0d6-90ba-4b72-8d83-edff03ac3482

Comment on lines +43 to +46
$a = $simpleXMLElement;
$a++;
$a = $simpleXMLElement;
--$a;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was allowed by the previous version of the rule as well (due to ObjectType::toNumber). And it does seem to work in PHP 8.3, but not in earlier versions. However, I don't see this change mentioned in the documentation. I'm not entirely sure how best to handle it, so I kept it allowed.

https://3v4l.org/DVmtc

Comment on lines +18 to +21
$classWithToString = new ClassWithToString();
$classWithToString++;
$classWithToString = new ClassWithToString();
--$classWithToString;
Copy link
Contributor Author

@schlndh schlndh Jul 20, 2024

Choose a reason for hiding this comment

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

Bug: This does work in PHP 7: https://3v4l.org/oXvs8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually works even without __toString(), but I'm not sure whether it can be used for anything useful with custom classes: https://3v4l.org/uXLrP I'd prefer to keep it disabled even for PHP 7 unless there is a use-case for it.

@schlndh schlndh marked this pull request as draft July 20, 2024 12:37
@schlndh schlndh marked this pull request as ready for review July 20, 2024 12:51
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit a1e697b into phpstan:1.11.x Jul 20, 2024
449 of 456 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@schlndh schlndh deleted the feature-stricterCheckingOfIncDecOperator branch July 21, 2024 05:40
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