+ if ( $recurse_objects ) {
+
+ // If no maximum recursion level is set, use the XDebug limit if it exists
+ if ( -1 == $max_recursion ) {
+ // Get the XDebug nesting level. Will be zero (no limit) if no value is set
+ $max_recursion = intval( ini_get( 'xdebug.max_nesting_level' ) );
+ }
+
+ // If we've reached the maximum recursion level, short circuit
+ if ( $max_recursion != 0 && $recursion_level >= $max_recursion ) {
+ WP_CLI::warning("Maximum recursion level of $max_recursion reached");
+ return $data;
+ }
+
+ if ( ( is_array( $data ) || is_object( $data ) ) ) {
+ // If we've seen this exact object or array before, short circuit
+ if ( in_array( $data, $visited_data, true ) ) {
+ return $data; // Avoid infinite loops when there's a cycle
+ }
+ // Add this data to the list of
+ $visited_data[] = $data;
+ }
+ }
+