Skip to content

Fetch for read in nested property assignments #12244

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

iluuu1994
Copy link
Member

$a->b->c = 'd';

is now compiled the same way as

$b = $a->b;
$b->c = 'd';

That is, we perform a read fetch on $a->b, rather than a write fetch.

This is possible, because PHP 8 removed auto-vivification support for objects, so $a->b->c = 'd' may no longer modify $a->b proper (i.e. not counting interior mutability of the object).

    $a->b->c = 'd';

is now compiled the same way as

    $b = $a->b;
    $b->c = 'd';

That is, we perform a read fetch on $a->b, rather than a write
fetch.

This is possible, because PHP 8 removed auto-vivification support
for objects, so $a->b->c = 'd' may no longer modify $a->b proper
(i.e. not counting interior mutability of the object).

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
@iluuu1994 iluuu1994 force-pushed the nested-fetch-obj-by-read branch from 6541e86 to fc488c6 Compare February 8, 2024 12:12
@iluuu1994
Copy link
Member Author

The fact that the lhs of -> is fetched using W/RW in these given contexts was actually really useful for data classes (#13800). So, I no longer want to make this change.

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.

1 participant