Autovivication prototype and investigation notes #17
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 is not the implementation for
https://wiki.php.net/rfc/autovivification_false - it is a quick and dirty
prototype to quickly check on the impact autovivication would have on production
applications. I am not involved in that RFC.
For $obj->dynamicProp[] = 123;
, they cannot currently be distinguishedfor undeclared properties because $obj->dynamicProp is converted to null when
fetching the property for purposes of assignment.
As a workaround, this prototype ignores null on dynamic object properties
to avoid false positives. (I assume an actual implementation for null would do something more robust and complicated such as add a new bit flag to indicate the property was created)
Zend/optimizer would need to be updated to account for the opcodes that can
now throw or have side effects such as emitting notices.
This quick and dirty prototype does not implement that.
There may be more issues with references.
There may be more opcodes.
Exception handling and memory management was not tested
$this->actuallyAnArray[$i0][$i1][$i2][$i3] = $var
is buggyFor php's tests of itself, null causes a lot more failures than false, e.g. https://github.com/php/php-src/blob/master/Zend/tests/gc_017.phpt
Static analyzers seem pretty effective, e.g. https://github.com/phan/phan had no issues when analyzing itself. Applications that don't use static analyzers or that don't have complete type information may encounter a lot more notices for null.