[PropertyAccess] Throw an UnexpectedTypeException when the type do not match#18210
Merged
Conversation
Member
|
👍 |
| } catch (\TypeError $e) { | ||
| try { | ||
| self::throwUnexpectedTypeException($e->getMessage(), $e->getTrace(), 0); | ||
| } catch (UnexpectedTypeException $e) { |
Member
There was a problem hiding this comment.
why is it thrown to catch it again ?
Member
Author
There was a problem hiding this comment.
throwing is done conditionally (see throwUnexpectedTypeException). Thus if the method throws, $e changes, otherwise $e stays as the original TypeError. This is exactly the logic we need here.
Member
There was a problem hiding this comment.
OK, I missed the rethrow below (this code should be cleaned to use finally instead in 3.0+)
Member
|
👍 |
Member
|
Thank you @nicolas-grekas. |
fabpot
added a commit
that referenced
this pull request
Mar 18, 2016
… type do not match (dunglas, nicolas-grekas) This PR was merged into the 2.3 branch. Discussion ---------- [PropertyAccess] Throw an UnexpectedTypeException when the type do not match | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17738, #18032 | License | MIT | Doc PR | - Made in coordination with @dunglas, Diff best viewed [ignoring whitspaces](https://github.com/symfony/symfony/pull/18210/files?w=1). Quoting #18032: > it appears that the current implementation is error prone because it throws a `\TypeError` that is an `Error` in PHP 7 but a regular `Exception` in PHP 5 because it uses the Symfony polyfill. Programs wrote in PHP 5 and catching all exceptions will catch this "custom" `\TypeError ` but not those wrote in PHP 7. It can be very hard to debug. > In this alternative implementation: > * catching type mismatch is considered a bug fix and applied to Symfony 2.3 > * for every PHP versions, a domain exception is thrown Commits ------- 5fe2b06 [PropertyAccess] Reduce overhead of UnexpectedTypeException tracking 10c8d5e [PropertyAccess] Throw an UnexpectedTypeException when the type do not match
Contributor
|
Isn't this a BC break? PHP 7 code that previously caught TypeError will not work anymore, or am I missing something? |
This was referenced Mar 25, 2016
Merged
Closed
Merged
Merged
Merged
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.
Made in coordination with @dunglas,
Diff best viewed ignoring whitspaces.
Quoting #18032: