-
Notifications
You must be signed in to change notification settings - Fork 20
support deprecated magic __toString() in echo statement #37
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
Conversation
tests/Rules/Deprecations/data/echo-deprecated-magic-method-tostring.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of this code is inspired by CallToDeprecatedMethodRule
tests/Rules/Deprecations/data/echo-deprecated-magic-method-tostring.php
Outdated
Show resolved
Hide resolved
Hi, this is rather incomplete and does not have rules for other situations.
What I recommend in your situation:
- Delete the deprecated
__toString()method from your code. - Run PHPStan to see all the usages.
- Remove the usages.
Thx for your feedback.
I am not sure how I should take it.
I am aware there are a lot of more things to take care of, but just want to get in contact early, since the very basic case which is important to me is already covered.
Was your suggestion about how I should proceed to get this rule into shape so you might consider merging it, or was your intention to give me a hint of how I should handle a possible deprecated __toString() method in my real world project (and you think this PR is not worth finishing)?
Thanks again
I want ahead and added more coverage for more complex expressions.
Just realized that this needs a lot more then I initially expected 😅
In case someone knows a expression I am missing feel free to sent me an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a followup step, I would extract this logic into a helper and add a separate rule for Print.
Additionally a Rule could be added for the string-concat case
...e with bleeding edge switch
hey ondrey,
thx again for your feedback. I tried to incorporate what I have understood so far.
I have extracted a new EchoDeprecatedBinaryOpToStringRule rule from the already existing one - I kept the initial implementation of EchoDeprecatedToStringRule untouched, but would extract more rules out of it, in case the newly added Rule looks like what you expect from it.
does this look good to you?
27397cd to
089d8a8
Compare
obsolete with phpstan/phpstan-src@ce257d9
Oh, not really this case 😊 But it could all work together with the new virtual nodes you proposed.
ok cool, so maybe we should re-open phpstan/phpstan#4899 so its not forgotten?
Uh oh!
There was an error while loading. Please reload this page.
with this change phpstan is able to detect cases, where object values are used in
echostatements and implicitly call a magic and deprecated__toStringmethod.In case this new rule gets accepted, I would be willing to implement the same for the
printstatement.refs phpstan/phpstan#4899