Skip to content

Conversation

@heathdutton
Copy link

When a DateInterval object has a circular reference (e.g., $obj->prop = $obj), calling json_encode() triggers an assertion failure in debug builds. This happens because the get_properties handler tries to modify the properties HashTable in place, but circular references cause the HashTable to have a refcount > 1, which violates the assertion in zend_hash_str_update().

This adds a get_properties_for handler for DateInterval that duplicates the properties array before adding the internal interval properties. This matches the existing pattern used by DateTime and DateTimeZone, which already have both handlers for the same reason.

The original get_properties handler is preserved for backward compatibility with get_object_vars().

Fixes GH-20503

…y hash

When a DateInterval object has a circular reference (e.g., $obj->prop = $obj), calling json_encode() triggered an assertion failure because the get_properties handler modified a HashTable with refcount > 1.

Added a get_properties_for handler for DateInterval that duplicates the properties array before modification, matching the pattern used by DateTime and DateTimeZone.
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.

Assertion failure with ext/date DateInterval property hash construction

1 participant