Skip to content

Formatting: Map ArrayObject entries in map_deep() - #14860

Open
benitoalba wants to merge 2 commits into
WordPress:trunkfrom
benitoalba:benitoalba/53160-map-deep-array-object
Open

benitoalba wants to merge 2 commits into
WordPress:trunkfrom
benitoalba:benitoalba/53160-map-deep-array-object

Conversation

@benitoalba

@benitoalba benitoalba commented Oct 25, 2026 •

Copy link
Copy Markdown

On PHP 7.4+, get_object_vars() excludes ArrayObject storage. map_deep() therefore skips those entries, which also leaves slashes or URL characters unchanged when its wrappers receive an ArrayObject.

Walk the stored entries explicitly, then keep the existing public-property traversal. STD_PROP_LIST still selects property-only handling, and the original flags and object identity are preserved. Tests cover nested containers, object-backed storage, empty instances, and all four Core wrappers that call map_deep().

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

Testing

Tested with PHP 8.3.36 and PHP 8.5.12, using PHPUnit 9.6.38:

  • Eight of the new cases fail on unchanged trunk because the stored values are never mapped.
  • PHP 8.3: all 22 focused tests pass with 45 assertions on single site and multisite. The full formatting group passes in randomized order (seed 53160): 2,206 tests and 1,118,564 assertions.
  • PHP 8.5: the focused tests pass on single site and multisite with 43 assertions and one version-gated skip. The full formatting group passes: 2,206 tests and 1,118,562 assertions, with the same skip.
  • Both formatting runs report five PHPUnit deprecation warnings in unchanged tests.
  • Full PHPStan 2.3.1 analysis, WordPress coding standards, PHP compatibility, and git diff --check pass.

The object-backed fixture runs only below PHP 8.5 because PHP 8.5 deprecated that constructor usage. All array-backed and public-property cases continue to run on PHP 8.5.

php vendor/bin/phpunit --no-logging tests/phpunit/tests/formatting/mapDeep.php
php vendor/bin/phpunit --no-logging --group formatting --order-by=random --random-order-seed=53160
php vendor/bin/phpunit --no-logging -c tests/phpunit/multisite.xml tests/phpunit/tests/formatting/mapDeep.php
php vendor/bin/phpstan analyse --no-progress --memory-limit=2G
php vendor/bin/phpcs src/wp-includes/formatting.php tests/phpunit/tests/formatting/mapDeep.php
php vendor/bin/phpcs --standard=phpcompat.xml.dist src/wp-includes/formatting.php tests/phpunit/tests/formatting/mapDeep.php

Use of AI Tools

AI assistance: Yes. OpenAI Codex researched the ticket, wrote the patch and tests, ran local validation, and drafted this description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@benitoalba
benitoalba marked this pull request as ready for review October 25, 2026 22:30
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

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

Props benitoalba.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

* Object-backed storage is deprecated as of PHP 8.5.
*
* @ticket 53160
* @requires PHP < 8.5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this works?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I retested this with PHPUnit 9.6.38 on PHP 8.3.36 and 8.5.12, on both single site and multisite. All 22 tests pass on 8.3. On 8.5, only this fixture skips, with PHP < 8.5 is required.

Removing the annotation makes the fixture fail on PHP 8.5 because new ArrayObject( $storage ) triggers the object-backed storage deprecation.

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.

2 participants