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

Throw less misleading exception when property access not found#19141

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

Closed
bramtweedegolf wants to merge1 commit intosymfony:masterfromtweedegolf:master
Closed

Conversation

@bramtweedegolf
Copy link
Contributor

@bramtweedegolfbramtweedegolf commentedJun 22, 2016
edited
Loading

Prevent throwing a NoSuchPropertyException with a somewhat misleading message "Neither the property "X" nor one of the methods "addX()"/"removeX()", "setX()", "x()", "__set()" or "__call()" exist and have public access in class when the access cannot be determined, for instance if the doctrine schema is not up to date.

QA
Branch?3.1 for fixes
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
LicenseMIT

@bramtweedegolf
Copy link
ContributorAuthor

bramtweedegolf commentedJun 22, 2016
edited
Loading

Sorry, status should not be bug but enhancement.

@stof
Copy link
Member

this should be covered by a test

@fabpot
Copy link
Member

I think that this qualifies as a bug fix. Can you add a test for that case?

$object->$property =$value;
}elseif (self::ACCESS_TYPE_NOT_FOUND ===$access[self::ACCESS_TYPE]) {
thrownewNoSuchPropertyException(sprintf('Could not determine access type for property "%s".',$property));
}elseif (self::ACCESS_TYPE_MAGIC ===$access[self::ACCESS_TYPE]) {
Copy link
Contributor

@phansysphansysJun 24, 2016
edited
Loading

Choose a reason for hiding this comment

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

Anelseif expression after an uncaught exception looks weird. IMHO, it should be more semantic to replace it with a newif.

sstok reacted with thumbs up emojinicolas-grekas reacted with thumbs down emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

@nicolas-grekas:Coding Standards > Structure

Do not use else, elseif, break after if and case conditions which return or throw something;

Copy link
Member

@nicolas-grekasnicolas-grekasAug 24, 2016
edited
Loading

Choose a reason for hiding this comment

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

I don't know what you have in mind but if you mean just turning this elseif into an if, then the code won't mean the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean a better form could be:

// ...}elseif (self::ACCESS_TYPE_NOT_FOUND ===$access[self::ACCESS_TYPE]) {thrownewNoSuchPropertyException(sprintf('Could not determine access type for property "%s".',$property));}if (self::ACCESS_TYPE_MAGIC ===$access[self::ACCESS_TYPE]) {$object->{$access[self::ACCESS_NAME]}($value);}else {// ...}

Choose a reason for hiding this comment

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

But this code doesn't do the same...

Copy link
Contributor

Choose a reason for hiding this comment

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

That would't be changed, I mean onlyelse/elseif blocks directly adjacent afterreturn orthrow statments (in this case,if (self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE]))

Copy link
Member

@nicolas-grekasnicolas-grekasAug 24, 2016
edited
Loading

Choose a reason for hiding this comment

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

I'm sorry but this is not the same... all conditions have to be checked before comming to that line, which means all previous conditions before have an impact on the conditions below. If you break the chain, you break the code...

Copy link
Contributor

Choose a reason for hiding this comment

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

The conditions after anif that evaluates totrue aren't checked (else /elseif) and the script flow stops when an uncaught exception is found, so which is the sense on having anelseif after a broken execution? IMO, this must be anif. I'm sharing a gist with the whole method just in order to clarify my thoughts:https://gist.github.com/phansys/42deea38ddcbc1d14b82654d92e8d7e0#file-propertyaccessor-php-L25

Choose a reason for hiding this comment

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

With your code, if!$access[self::ACCESS_HAS_PROPERTY] && property_exists($object, $property) is true, an exception will be thrown anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Very good, finally I get your point. Sorry for the misunderstanding and thank you for the time you took to explain this.

nicolas-grekas reacted with hooray emoji
@nicolas-grekas
Copy link
Member

ping@bramtweedegolf

@nicolas-grekas
Copy link
Member

Status: needs work

// fatal error.

$object->$property =$value;
}elseif (self::ACCESS_TYPE_NOT_FOUND ===$access[self::ACCESS_TYPE]) {

Choose a reason for hiding this comment

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

@bramtweedegolf can you please move this elseif one step down, to put all throwing cases at the end?

@fabpot
Copy link
Member

@bramtweedegolf Can you take the latest comments into account and add some unit tests to finish this PR? Thanks.

@nicolas-grekasnicolas-grekas added this to the3.1 milestoneDec 6, 2016
@nicolas-grekas
Copy link
Member

Thank you@bramtweedegolf.

nicolas-grekas added a commit that referenced this pull requestDec 8, 2016
…ound (bramtweedegolf)This PR was submitted for the master branch but it was merged into the 3.1 branch instead (closes#19141).Discussion----------Throw less misleading exception when property access not foundPrevent throwing a NoSuchPropertyException with a somewhat misleading message "Neither the property "X" nor one of the methods "addX()"/"removeX()", "setX()", "x()", "__set()" or "__call()" exist and have public access in class when the access cannot be determined, for instance if the doctrine schema is not up to date.| Q | A || --- | --- || Branch? | 3.1 for fixes || Bug fix? | no || New feature? | no || BC breaks? | no || Deprecations? | no || Tests pass? | yes || License | MIT |Commits-------ec28da4 Throw less misleading exception when property access not found
This was referencedDec 13, 2016
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

3.1

Development

Successfully merging this pull request may close these issues.

6 participants

@bramtweedegolf@stof@fabpot@nicolas-grekas@phansys@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp