Make WordPress Core

Opened 7 months ago

Last modified 35 hours ago

#57067 new enhancement

Replace certain `array_key_exists()` calls with `isset()` once PHP requirement is raised to 7.0+

Reported by: flixos90's profile flixos90 Owned by:
Milestone: 6.3 Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch
Focuses: performance Cc:

Description

This ticket is blocked until WordPress requires at least PHP 7.0 as minimum version.

Checks like isset( MY_CONSTANT[ $key ] ) result in a fatal error in PHP < 7.0, which is why parts of the WordPress codebase uses array_key_exists() for such situations as of today, due to the support for PHP 5.6. Also see https://github.com/PHPCompatibility/PHPCompatibility/issues/1301 which explores flagging this as part of the PHPCompatibility sniffs.

This was raised as part of #56974, which reviewed several of these checks. isset is slightly preferable over array_key_exists in terms of performance (with the caveat that the two behave differently when it comes to null values).

As of today, this ticket is essentially a reminder to update such calls to array_key_exists() in WordPress core once it will at some point no longer support PHP versions below 7.0.

Change History (8)

#1 @flixos90
7 months ago

cc @jrf @aristath @desrosj

#2 @flixos90
7 months ago

In 54804:

Editor: Improve performance of WP_Theme_JSON class by reducing usage of expensive array functions.

In many scenarios array functions are more expensive than using simpler for or foreach loops.

This changeset results in roughly 4% faster wp_head execution time for both block themes and classic themes. While this may seem like a small win, it is a worthwhile enhancement and only one part of several other little performance tweaks which are being worked on to improve performance of theme.json parsing further.

Props aristath, desrosj, jrf, spacedmonkey.
Fixes #56974.
See #57067.

#3 @flixos90
7 months ago

In 54805:

Editor: Improve performance of WP_Theme_JSON class by reducing usage of expensive array functions.

In many scenarios array functions are more expensive than using simpler for or foreach loops.

This changeset results in roughly 4% faster wp_head execution time for both block themes and classic themes. While this may seem like a small win, it is a worthwhile enhancement and only one part of several other little performance tweaks which are being worked on to improve performance of theme.json parsing further.

Props aristath, desrosj, jrf, spacedmonkey.
Merges [54804] to the 6.1 branch.
Fixes #56974.
See #57067.

This ticket was mentioned in PR #3907 on WordPress/wordpress-develop by @Mamaduka.


4 months ago
#4

  • Keywords has-patch added

PR fixes a small regression after 54805, where an incorrect variable was used inside the loop.

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

#5 @flixos90
4 months ago

In 55142:

Editor: Fix undefined variable following [54805].

Props mamaduka, costdev, mukesh27.
See #56974, #57067.

#7 @johnbillion
3 weeks ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Future Release to 6.3

#8 @joemcgill
35 hours ago

The effort to bump the minimum version of PHP is being tracked in #57345, which is blocking this ticket. Even so, it would be good to have a patch ready and reviewed so it can be committed as soon as the official decision to drop PHP 5.6 has been made.

Last edited 35 hours ago by joemcgill (previous) (diff)
Note: See TracTickets for help on using tickets.