Skip to content

Comments

Update the array_is_list compat function, add tests#6028

Closed
swissspidy wants to merge 4 commits intoWordPress:trunkfrom
swissspidy:fix/55105-tests
Closed

Update the array_is_list compat function, add tests#6028
swissspidy wants to merge 4 commits intoWordPress:trunkfrom
swissspidy:fix/55105-tests

Conversation

@swissspidy
Copy link
Member

The function was polyfilled via another ticket.

This adds tests that were originally added and simplifies the polyfill (assuming the tests still pass)

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


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.

@swissspidy swissspidy requested a review from costdev February 5, 2024 15:47
@github-actions
Copy link

github-actions bot commented Feb 5, 2024

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 SVN

If you're a Core Committer, use this list when committing to wordpress-develop in SVN:

Props: swissspidy, costdev.

GitHub Merge commits

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: swissspidy <swissspidy@git.wordpress.org>
Co-authored-by: costdev <costdev@git.wordpress.org>

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

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for putting the PR together @swissspidy!

I'm happy to go with the shorter function contents, though I haven't had a chance to compare both approaches on large arrays. It would be good to get some benchmarks on that if possible, but not a blocker.

LGTM 👍

@github-actions
Copy link

github-actions bot commented Feb 5, 2024

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@swissspidy
Copy link
Member Author

Okay so the shorter version fails for the array(NAN) case on PHP 7.0 and PHP 7.1

Benchmarking with a larger array now. Turns out the array_values() approach is faster for the happy path, see https://3v4l.org/EMpT0/perf (foreach) vs https://3v4l.org/1WsAV/perf (array_values())

For the unhappy path the performance seems equal, see https://3v4l.org/5YMl2/perf (foreach), https://3v4l.org/o1SSY/perf (array_values()) and https://3v4l.org/H721m/perf (both).

So that appears to make a case for using both as Symfony does.

@costdev
Copy link
Contributor

costdev commented Feb 5, 2024

Not sure how both can ever be run though. If array_values( $arr ) === $arr, then when would the foreach() run?

@swissspidy
Copy link
Member Author

@costdev It's specifically that the output for using array( NAN ) as the input is different on PHP 7.0 and PHP 7.1. It doesn't really make sense to me.

See https://3v4l.org/nPN8l

@swissspidy
Copy link
Member Author

Tests committed in https://core.trac.wordpress.org/changeset/57535

@swissspidy swissspidy closed this Feb 5, 2024
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