[wp-trac] [WordPress Trac] #62558: Add PHP 8.4 compat array functions: `array_find`, `array_find_key`, `array_any` and `array_all`

WordPress Trac noreply at wordpress.org
Fri Feb 7 14:42:07 UTC 2025


#62558: Add PHP 8.4 compat array functions: `array_find`, `array_find_key`,
`array_any` and `array_all`
------------------------------------------------+--------------------------
 Reporter:  Soean                               |       Owner:  (none)
     Type:  feature request                     |      Status:  new
 Priority:  normal                              |   Milestone:  6.8
Component:  General                             |     Version:
 Severity:  normal                              |  Resolution:
 Keywords:  has-patch php84 add-to-field-guide  |     Focuses:  php-
                                                |  compatibility
------------------------------------------------+--------------------------
Changes (by desrosj):

 * keywords:  has-patch php84 add-to-field-guide changes-requested => has-
     patch php84 add-to-field-guide


Comment:

 Replying to [comment:5 ayeshrajans]:
 > Do we have a guideline on which functions we polyfill, and which we
 don't?

 We don't currently have any official guidance in the handbook. Perhaps
 that's a good thing to add. If I had to write up that section today, this
 is what I would list as the criteria used to weigh when evaluating whether
 to include a PHP language polyfill:
 - Polyfill code size
 - How self contained is the polyfill? It should serve a single-
 responsibility unless absolutely necessary (we want to avoid adding entire
 polyfill classes and libraries as much as possible).
 - How many old code patterns does the polyfill replace in favor of
 consistency?
 - Performance improvement compared to these older patterns. Large
 improvements lend to the polyfill being a strong progressive enhancement
 that plugin and theme developers can count on being available.
 - Does the new function protect against common mistakes? For example,
 `str_contains()` guarding against scenarios where `if ( strpos( 'This is a
 haystack', 'This' ) )` is evaluated as falsey.
 - Are these old patterns prevalent throughout Core? Would the polyfill
 help remove a good amount of duplicate code?
 - Maintenance burden of adding a polyfill. It should be simple to remove
 later.
 - The range of PHP versions currently supported. For example, if something
 is added in 8.4, a polyfill would currently allow for supporting the new
 function in 7 additional PHP versions.

 In the case of these functions, it's difficult to find occurrence in Core
 where this would be useful, but I think it's a reasonable assumption there
 are a good number of instances where this would be useful. But it will
 require a more manual effort.

 The PR looks good to me, I just approved it. I would love to give the
 opportunity for @joemcgill and @Mamaduka to weigh in as my fellow Core
 Tech Leads for 6.8 in case they have any opposing opinions.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62558#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list