Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PropertyAccess] Throw an UnexpectedTypeException when the type do not match#18210

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 2 commits intosymfony:2.3fromnicolas-grekas:pax
Mar 18, 2016

Conversation

@nicolas-grekas
Copy link
Member

QA
Branch?2.3
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#17738,#18032
LicenseMIT
Doc PR-

Made in coordination with@dunglas,
Diff best viewedignoring whitspaces.

Quoting#18032:

it appears that the current implementation is error prone because it throws a\TypeError that is anError in PHP 7 but a regularException 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

@dunglas
Copy link
Member

👍

}catch (\TypeError$e) {
try {
self::throwUnexpectedTypeException($e->getMessage(),$e->getTrace(),0);
}catch (UnexpectedTypeException$e) {
Copy link
Member

Choose a reason for hiding this comment

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

why is it thrown to catch it again ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I missed the rethrow below (this code should be cleaned to usefinally instead in 3.0+)

@fabpot
Copy link
Member

👍

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commit5fe2b06 intosymfony:2.3Mar 18, 2016
fabpot added a commit that referenced this pull requestMar 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 thrownCommits-------5fe2b06 [PropertyAccess] Reduce overhead of UnexpectedTypeException tracking10c8d5e [PropertyAccess] Throw an UnexpectedTypeException when the type do not match
@nicolas-grekasnicolas-grekas deleted the pax branchMarch 18, 2016 10:21
@Tobion
Copy link
Contributor

Isn't this a BC break? PHP 7 code that previously caught TypeError will not work anymore, or am I missing something?

discordier reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@nicolas-grekas@dunglas@fabpot@Tobion@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp