Remove auto-vivification for objects #3865
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 astdClass
. 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()
andoffsetGet()
, 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.