[deprecation] Deprecate JsonThrowOnErrorRector as it can cause BC breaks - #8327
Merged
Conversation
Adding JSON_THROW_ON_ERROR turns silent false/null results into a thrown JsonException. Every call site has to be reviewed by hand, so the change needs manual care instead. Use a wrapper tool like nette/utils Json for clear error reporting on any PHP version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Deprecates
JsonThrowOnErrorRector, following the same pattern as #8324.The rule adds
JSON_THROW_ON_ERRORto everyjson_encode()/json_decode()call:This is a BC break, not a cleanup. Before the change a malformed payload returns
falseornull; after it, the same payload throwsJsonException. Code that relied on the silent return value now fatals at runtime:Every call site has to be reviewed by hand to decide whether an exception is wanted and where it gets caught. Rector cannot make that call, so the rule is deprecated instead. For consistent error reporting on any PHP version, a wrapper tool like
nette/utilsJson::decode()is the better fit.The rule was in no set, so no user config is silently affected.
Changes:
JsonThrowOnErrorRectorimplementsDeprecatedInterface,refactor()throwsShouldNotHappenExceptiontests/Issues/ScopeNotAvailable/JsonThrowCaseSensitiveConstFetchTest.php, a regression test that only existed to cover this rule