Skip to content

Make var_export/debug_zval_dump check for infinite recursion on the *object* #9448

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

Merged

Conversation

TysonAndre
Copy link
Contributor

Switch the recursion check from the result of get_properties_for
(the returned hash table of properties) to just checking for
infinite recursion on the object.

  • In order for a native datastructure to correctly implement
    *get_properties_for for var_export's cycle detection,
    it would need to return the exact same array every time prior to this PR.

    Prior to this commit, the requirements for cycle detection
    would prevent SplFixedArray or similar classes from returning a
    temporary array that:

    1. Wouldn't be affected by unexpected mutations from error handlers
    2. Could be garbage collected instead.

Note that SplFixedArray continues to need to return object->properties
until php 9.0, when dynamic properties are forbidden.
(even after php 9.0, because #[\AllowDynamicProperties] can be used in subclasses?)

This is the same as #8046 ,
which was accidentally deleted after deleting a similar branch name of an earlier version of this.

Note that an earlier commit already introduced ext/spl/tests/fixedarray_022.phpt with the same test case contents for the original bug


Thankfully, #8046 (comment) are the only remaining issues I'm aware of after the last bug fix https://github.com/php/php-src/pull/8105/files
(delayed __destruct of elements after a var_export call on a collection followed by change such as remove()/pop(), extra memory usage on internal data structures such as SPL after a var_export call, poor worst-case performance for cycle detection in var_export and related functions)

…object*

Switch the recursion check from the result of `get_properties_for`
(the returned hash table of properties) to just checking for
infinite recursion on the object.

- In order for a native datastructure to correctly implement
  `*get_properties_for` for var_export's cycle detection,
  it would need to return the exact same array every time prior to this PR.

  Prior to this commit, the requirements for cycle detection
  would prevent SplFixedArray or similar classes from returning a
  temporary array that:

  1. Wouldn't be affected by unexpected mutations from error handlers
  2. Could be garbage collected instead.

Note that SplFixedArray continues to need to return `object->properties`
~~until php 9.0, when dynamic properties are forbidden.~~
(even after php 9.0, because `#[\AllowDynamicProperties]` can be used in subclasses?)
@TysonAndre
Copy link
Contributor Author

This was approved in #8046

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