Skip to content

Remove auto-vivification for objects #3865

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 2 commits into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Feb 20, 2019

This PR contains two related changes: First, remove support for auto-vivification of objects. This means that $a->b = $c where $a is falsy will no longer automatically convert $a into a stdClass. Instead it will issue an "attempt to modify property of a non-object" warning and leave $a as-is.

Second, as $a->b = $c may no longer modify the storage location of $a (only the object contained in it), $a will now be fetched for read rather than for write. This distinction is particularly important in conjunction with __get() and offsetGet(), as it avoids spurious "indirect modification" warnings, where no modification actually takes place.

Unfortunately this patch also breaks $foo->bar[0]->baz = "foo" style assignments in SimpleXML, where previously all the relevant children were implicitly created. I'll have to look into whether this can be still be supported with read fetches or not.

@nikic nikic added the RFC label Feb 20, 2019
This contains two changes:
 * $foo->bar = $baz where $foo is falsy no longer converted $foo
   into an stdClass.
 * As a result of this change, in $a->b->c = $d we now treat the
   access $a->b as a read and only ->c = $d as a write, resolving
   some long-standing issues with bogus "indirect modification"
   warnings.
@nikic nikic force-pushed the no-implicit-object-init branch from 9e99feb to 6c2e453 Compare February 20, 2019 11:32
@nikic
Copy link
Member Author

nikic commented Sep 26, 2019

This is mostly superseded by #4745. That PR does not change the fetch mode from W to R, because of the SimpleXML issue. It would still be good to get that working somehow...

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

Successfully merging this pull request may close these issues.

1 participant