Skip to content

Handle array-like unserialized objects without dynamic property writes#237

Merged
swissspidy merged 3 commits into
mainfrom
copilot/fix-deprecation-notices
May 20, 2026
Merged

Handle array-like unserialized objects without dynamic property writes#237
swissspidy merged 3 commits into
mainfrom
copilot/fix-deprecation-notices

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

PHP 8.2 surfaces deprecation notices when search-replace recurses into unserialized array-like objects such as WpOrg\Requests\Utility\CaseInsensitiveDictionary. The current recursion path also writes replacements back incorrectly for these objects by assigning dynamic properties instead of updating their underlying dictionary storage.

  • What changed

    • Updated SearchReplacer object recursion to detect ArrayAccess objects and write replaced values back through array-style offsets.
    • Kept the existing property-assignment path for regular objects unchanged.
  • Why this matters

    • Avoids PHP 8.2 dynamic property deprecations for iterable dictionary-like objects.
    • Preserves actual replacement behavior for serialized response/header objects instead of mutating undeclared properties.
  • Regression coverage

    • Added a Behat scenario for serialized WpOrg\Requests\Utility\CaseInsensitiveDictionary data.
    • Verifies recursive replacement updates the serialized payload without emitting stderr noise.
foreach ( $data as $key => $value ) {
	$value = $this->run_recursively( $value, false, $recursion_level + 1, $visited_data );

	if ( $data instanceof \ArrayAccess ) {
		$data[ $key ] = $value;
	} else {
		$data->$key = $value;
	}
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/search-replace-command/search-replace-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@github-actions github-actions Bot added bug command:search-replace Related to 'search-replace' command scope:testing Related to testing state:unconfirmed labels May 19, 2026
Copilot AI changed the title [WIP] Fix deprecation notices when unserializing array-like objects Handle array-like unserialized objects without dynamic property writes May 19, 2026
Copilot AI requested a review from swissspidy May 19, 2026 14:51
Copilot AI linked an issue May 19, 2026 that may be closed by this pull request
2 tasks
@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review May 19, 2026 16:49
@swissspidy swissspidy requested a review from a team as a code owner May 19, 2026 16:49
Copilot AI review requested due to automatic review settings May 19, 2026 16:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SearchReplacer’s recursive object handling to avoid PHP 8.2 dynamic-property deprecation notices and to correctly write replaced values back into array-like objects (e.g., ArrayAccess-based dictionaries) using offset assignment.

Changes:

  • Updated recursive replacement for iterated objects to write back via $data[$key] = ... when the object implements \ArrayAccess.
  • Preserved the existing property-assignment path for non-\ArrayAccess objects.
  • Added a Behat regression scenario covering serialized WpOrg\Requests\Utility\CaseInsensitiveDictionary replacement and ensuring no stderr output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/WP_CLI/SearchReplacer.php Adjusts object recursion to update ArrayAccess objects via offsets instead of dynamic properties.
features/search-replace.feature Adds an acceptance test scenario to validate correct behavior and avoid PHP 8.2 deprecation noise.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/WP_CLI/SearchReplacer.php
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 19, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php /usr/bin/php /home/REDACTED/work/search-replace-command/search-replace-command/vendor/wp-cli/wp-cli/bin/../php/boot-fs.php core install --url=REDACTED --title=WP CLI Site --admin_user=admin --admin_email=admin@example.com --admin_password=password1 --skip-email (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@swissspidy swissspidy added this to the 2.1.13 milestone May 20, 2026
@swissspidy swissspidy requested a review from Copilot May 20, 2026 11:29
@swissspidy
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the SearchReplacer to correctly handle objects implementing \ArrayAccess during recursive search and replace operations. By checking for \ArrayAccess and using array syntax for assignment where appropriate, the change avoids potential dynamic property deprecation warnings and ensures compatibility with dictionary-like objects. A new test scenario was added to verify this behavior using CaseInsensitiveDictionary. I have no feedback to provide as there were no review comments.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@swissspidy swissspidy merged commit 4fae0da into main May 20, 2026
65 of 66 checks passed
@swissspidy swissspidy deleted the copilot/fix-deprecation-notices branch May 20, 2026 12:40
swissspidy added a commit that referenced this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:search-replace Related to 'search-replace' command scope:testing Related to testing state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP v8.2: Deprecation notices when unserializing array-like objects

3 participants