Skip to content

Don't call __set() on uninitialized typed properties #4854

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Oct 24, 2019

New stab at bug #78226: We introduce a type flag that distinguishes an uninitialized typed property and a property that has been explicitly unset(). Assigning to an uninitialized property will initialize the property and not invoke __set(). Assigning to an explicitly unset property will invoke __set().

This should be a compromise that both avoids WTF when using typed properties in a class with __set(), while still keeping @Ocramius's ProxyManager code working.

The patch turned out to be fairly non-intrusive, but it does disable an optimization for refcounted checks.

@nikic
Copy link
Member Author

nikic commented Oct 24, 2019

This is a followup to #4696. cc @marandall @trowski @morrisonlevi

<?php

class Test {
public int $foo;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a field that is not typed, so we verify the behavior for that as well? It shouldn't be an issue, but it does indeed prevent a regression

Copy link
Member

@trowski trowski left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! This patch makes __set() behavior intuitive with uninitialized typed properties.

@nikic
Copy link
Member Author

nikic commented Oct 25, 2019

Closing in favor of #4856.

@nikic nikic closed this Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants