Bleeding edge: stricter ++/-- operator check#3255
Bleeding edge: stricter ++/-- operator check#3255ondrejmirtes merged 1 commit intophpstan:1.11.xfrom
Conversation
| $a = $simpleXMLElement; | ||
| $a++; | ||
| $a = $simpleXMLElement; | ||
| --$a; |
There was a problem hiding this comment.
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.
| $classWithToString = new ClassWithToString(); | ||
| $classWithToString++; | ||
| $classWithToString = new ClassWithToString(); | ||
| --$classWithToString; |
There was a problem hiding this comment.
Bug: This does work in PHP 7: https://3v4l.org/oXvs8
There was a problem hiding this comment.
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.
|
This pull request has been marked as ready for review. |
|
Thank you! |
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