Skip to content

Autovivication prototype and investigation notes #17

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

TysonAndre
Copy link
Owner

@TysonAndre TysonAndre commented Jun 5, 2021

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.

  1. For $obj->dynamicProp[] = 123;, they cannot currently be distinguished
    for 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)

  2. 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.

  3. There may be more issues with references.

  4. There may be more opcodes.

  5. Exception handling and memory management was not tested

  6. $this->actuallyAnArray[$i0][$i1][$i2][$i3] = $var is buggy

For 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.

**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.**

1. `For $obj->dynamicProp[] = 123;`, they cannot currently be distinguished
   for 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.
2. 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.
3. There may be more issues with references.
4. There may be more opcodes.
5. Exception handling and memory management was not tested
@TysonAndre
Copy link
Owner Author

https://wiki.php.net/rfc/autovivification_false was merged into php 8.1 based on this

@TysonAndre TysonAndre closed this Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant