Skip to content

Allow readonly properties to be reinitialized once during cloning #10389

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

Merged
merged 6 commits into from
Feb 28, 2023

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Jan 20, 2023

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

I'm only halfway through the review, the rest will follow 🙂

@kocsismate kocsismate force-pushed the readonly-clone-reinit branch from d6bbf1a to 1aa6fe5 Compare February 24, 2023 10:57
@kocsismate
Copy link
Member Author

I rebased to current master + pushed a new commit fixing some of the review comments

@kocsismate kocsismate force-pushed the readonly-clone-reinit branch from c10c4cd to 75d4d9d Compare February 27, 2023 23:10
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

LGTM!

@kocsismate kocsismate merged commit 3bcf2c3 into php:master Feb 28, 2023
@kocsismate kocsismate deleted the readonly-clone-reinit branch February 28, 2023 21:56
@kocsismate kocsismate mentioned this pull request Mar 3, 2023
@@ -833,6 +828,16 @@ ZEND_API zval *zend_std_write_property(zend_object *zobj, zend_string *name, zva
variable_ptr = &EG(error_zval);
goto exit;
}
if (UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
Copy link
Member

Choose a reason for hiding this comment

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

I just realized that this is actually wrong. if (UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) { should be done before zend_verify_property_type, because otherwise side-effects like __toString() will run even if the property cannot be assigned. Z_PROP_FLAG_P(variable_ptr) &= ~IS_PROP_REINITABLE; however should be run after. @kocsismate Can you adjust that?

Copy link
Member Author

Choose a reason for hiding this comment

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

@iluuu1994 Yes, sure. I actually had the very same implementation initially for a few minutes, just to switch it to the current implementation. :)

Copy link
Member

Choose a reason for hiding this comment

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

Adding a test should be simple enough. Create a class with __toString and assign to a readonly property that's already initialized.

Copy link
Member Author

@kocsismate kocsismate Mar 3, 2023

Choose a reason for hiding this comment

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

Yep, I have already created a similar test case locally :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants