Add array_first() and array_last() in compat.php#9556
Add array_first() and array_last() in compat.php#9556USERSATOSHI wants to merge 9 commits intoWordPress:trunkfrom
array_first() and array_last() in compat.php#9556Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
I've added a few minor notes inline.
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Add missing ticket annotations
| /** | ||
| * Test that array_first() is always available (either from PHP or WP). | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * Test that array_first() is always available (either from PHP or WP). | |
| */ | |
| /** | |
| * @ticket 63853 | |
| * | |
| * Test that array_first() is always available (either from PHP or WP). | |
| */ |
There was a problem hiding this comment.
oh, I didn't know, it has to be there too. thank you
| /** | ||
| * Test that array_last() is always available (either from PHP or WP). | ||
| */ |
There was a problem hiding this comment.
| /** | |
| * Test that array_last() is always available (either from PHP or WP). | |
| */ | |
| /** | |
| * @ticket 63853 | |
| * | |
| * Test that array_last() is always available (either from PHP or WP). | |
| */ |
|
Hi, I have a question ( not related to ticket but related to tests). Is there a guidelines on how tests comments are to be written as when I checked the tests files for PHPUnit, some files have comments as well as ticket mentioned but others either don't have any comments nor the tickets. |
|
Here's the PHP implementation for reference: https://github.com/php/php-src/blob/0bf295944df7171acf47502d31dd7df8b9155d81/ext/standard/array.c#L4528-L4552 |
It's a bit of mixed bag but something contributors are working toward improving. It's become relatively common for contribuitors to use the order listed in the description of this trac ticket. |
Oh, got it! 👍, I will follow this format from now on. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
This looks good to me, thank you!
Add polyfills for
array_first()andarray_last(), planned for PHP 8.5. These provide a safe, side-effect-free way to fetch the first and last values of an array. This forward-compatibility makes it easier for Core, plugins, and themes to adopt upcoming PHP features while maintaining support for older versions.The PR includes the polyfills for both functions in
compat.phpas well as unit tests.Trac ticket: https://core.trac.wordpress.org/ticket/63853
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.