PHPC-1092: Don't reset hash on successive get_properties calls #734
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.
https://jira.mongodb.org/browse/PHPC-1092
This removes a call to
zend_hash_clean()
on successive calls to a BSON object'sget_properties
handler, which can lead to an infinite loop when iterating the object's properties with foreach on PHP 7.x.For historical reference, the original call to
zend_hash_clean()
was introduced in ad1f3f0 for #607 (PHPC-939).Note: I've only added tests for BSON classes that have a custom
get_properties
handler and utilize thePHONGO_GET_PROPERTY_HASH_INIT_PROPS()
macro. I do not recall why I originally addedzend_clean_hash()
, but I assume I was trying to be strict about not inheriting hash state from previous calls.While testing this, I was surprised to find that iterating the object with
foreach
actually invokesget_properties
multiple times. If I had to guess, the fact thatzend_hash_clean()
resets the hash pointer was causingforeach
to never advance past the first property.