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] Fix accessing dynamic properties#37622

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 1 commit intosymfony:5.1fromandreyserdjuk:master
Aug 26, 2020

Conversation

@andreyserdjuk
Copy link
Contributor

@andreyserdjukandreyserdjuk commentedJul 20, 2020
edited by nicolas-grekas
Loading

QA
Branch?5.1 (to be switched when merging)
Bug fix?yes
New feature?no
Deprecations?no
TicketsFix#37026
LicenseMIT
Doc PRno

@nicolas-grekas
Copy link
Member

/cc@joelwurtz@Korbeil WDYT?

On my side, I'm wondering about the perf impact of the implementation. Isn't this the same as removing the$object instanceof \stdClass check?

Please also add tests.

@nicolas-grekasnicolas-grekas added this to the5.1 milestoneJul 22, 2020
@nicolas-grekasnicolas-grekas changed the titleUpdated PropertyAccessor to access public properties for other classes[PropertyAccess] Fix accessing dynamic propertiesJul 22, 2020
@andreyserdjuk
Copy link
ContributorAuthor

andreyserdjuk commentedJul 22, 2020
edited
Loading

@nicolas-grekas it will fail when trying to access protected/private property ($access is null but we dunno why: it's a dynamic object property or class protected/private inaccessible property). The only reason why \stdClass check was written before - to be 100% sure that class property is dynamic and cannot be private/protected - inaccessible.
To improve performance I suggest havingPropertyReadInfo in any case to make a decision looking onPropertyReadInfo::$visibility. But it requires some refactoring.
BTW setValue() has the same logic. So I guess it also should support dynamic value?

@andreyserdjuk
Copy link
ContributorAuthor

Update: unit-test added. But only PropertyAccessor::getValue() is covered with getting dynamic value. setValue() - I didn't cover and as I see from unit-tests, the dynamic value cannot be set by design - at least setter method should be.
@dunglas , could you please tell (you created ReflectionExtractor), whether support of dynamic values getting/setting by ref evolutionally (and intentionally) was removed? I just want to be sure not to harm the idea of this tool.

@joelwurtz
Copy link
Contributor

I'm not sure about perf also, it may be slower (but need benchmark for that)

Another possible implementation would be to follow@nicolas-grekas suggestion by only removing the instanceof part and add a try catch when getting the value (to catch error if property is not accessible : protected / private), maybe it would keep perf reasonable and would also allow a better error message (like property exists but is not accessible)

@andreyserdjuk
Copy link
ContributorAuthor

@nicolas-grekas please review the last approach suggested by@joelwurtz .

}
}catch (\Error$e) {
if (!$ignoreInvalidProperty) {
thrownewNoSuchPropertyException(sprintf('Can\'t read protected or private property "%s" in class "%s".',$property,$class));
Copy link
Contributor

Choose a reason for hiding this comment

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

you can add the error in the parent exception

Copy link
ContributorAuthor

@andreyserdjukandreyserdjukAug 2, 2020
edited
Loading

Choose a reason for hiding this comment

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

I've added a previous exception as an argument, hope I've got you right.

@fabpot
Copy link
Member

Thank you@andreyserdjuk.

@fabpotfabpot merged commit92cb709 intosymfony:5.1Aug 26, 2020
@fabpot
Copy link
Member

Reverting this PR as it breaks things by bypassing a lot of logic. One such example is when you have a class with a private property AND a __get method to access it (like TestClassMagicGet in our test suite). Before this PR, if you disable magic __get method, you will get an expected NoSuchPropertyException. But now, the property_exists() call will return true, and $object->$property will get the value because there is a __get method (which the code explicitly disallow).

fabpot added a commit that referenced this pull requestAug 30, 2020
…(andreyserdjuk)"This reverts commit92cb709, reversingchanges made tofc3095f.
fabpot added a commit that referenced this pull requestAug 30, 2020
* 5.1:  Revert "bug#37622 [PropertyAccess] Fix accessing dynamic properties (andreyserdjuk)"
@fabpotfabpot mentioned this pull requestAug 31, 2020
@Voetloos
Copy link

Issue#37615 is again an issue since this is reverted. Any update on that?@fabpot@xabbuh@nicolas-grekas

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

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot approved these changes

@dunglasdunglasAwaiting requested review from dunglas

@jderussejderusseAwaiting requested review from jderusse

@lyrixxlyrixxAwaiting requested review from lyrixx

@srozesrozeAwaiting requested review from sroze

@xabbuhxabbuhAwaiting requested review from xabbuh

+2 more reviewers

@joelwurtzjoelwurtzjoelwurtz left review comments

@maxheliasmaxheliasmaxhelias approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.1

Development

Successfully merging this pull request may close these issues.

Recover support to write properties for non stdClass objects

8 participants

@andreyserdjuk@nicolas-grekas@joelwurtz@fabpot@Voetloos@maxhelias@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp