Skip to content

Conversation

himanshupathak95
Copy link

Trac ticket: https://core.trac.wordpress.org/ticket/30430

Objects stored in arrays within WP_Object_Cache were sharing references with the original data, causing unexpected mutations when either the original or cached data was modified.

This change adds deep copying functionality to properly clone objects nested within arrays at any level, ensuring cached data remains isolated from the original data structures.

Changes:

  • Add deep_copy() method for recursive object cloning in arrays
  • Update set() method to deep copy arrays containing objects
  • Update get() method to deep copy arrays when retrieving from cache
  • Add unit tests covering shallow and deep nesting scenarios

Fixes reference sharing issue while maintaining performance for primitive arrays.

Follows the implementation of the patch - https://core.trac.wordpress.org/attachment/ticket/30430/wp-deep-copy-withclass2.diff

@himanshupathak95 himanshupathak95 marked this pull request as ready for review September 5, 2025 08:13
Copy link

github-actions bot commented Sep 5, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props abcd95.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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