Skip to content

Commit cff118c

Browse files
committed
WP 5.9: account for new function polyfills
WP 5.9 contains polyfills for five new PHP native functions: * `array_key_first()` and `array_key_last()`, which were both introduced in PHP 7.3. * `str_contains()`, `str_starts_with()` and `str_ends_with()`, which were introduced in PHP 8.0. While the PHP 8.0 functions are not yet flagged by the latest release of PHPCompatibility, they will be once PHPCompatibility 10.0 comes out. As `exclude`-ing error codes which don't exist yet does not lead to errors in PHPCS, we may as well add the exclusions for all WP 5.9 polyfills in one go. Refs: * https://core.trac.wordpress.org/changeset/52038 * https://core.trac.wordpress.org/changeset/52039 * https://core.trac.wordpress.org/changeset/52040 * https://core.trac.wordpress.org/browser/trunk/src/wp-includes/compat.php#L398-L479
1 parent 80cb451 commit cff118c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

PHPCompatibilityWP/ruleset.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
* is_iterable(): since WP 4.9.6
2828
* is_countable(): since WP 4.9.6
2929
* IMAGETYPE_WEBP and IMG_WEBP: since WP 5.8.0.
30+
* array_key_first(): since WP 5.9.0
31+
* array_key_last(): since WP 5.9.0
32+
* str_contains(): since WP 5.9.0
33+
* str_starts_with(): since WP 5.9.0
34+
* str_ends_with(): since WP 5.9.0
3035
-->
3136
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.hash_hmacFound"/>
3237
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_encodeFound"/>
@@ -40,6 +45,11 @@
4045
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.is_countableFound"/>
4146
<exclude name="PHPCompatibility.Constants.NewConstants.imagetype_webpFound"/>
4247
<exclude name="PHPCompatibility.Constants.NewConstants.img_webpFound"/>
48+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_key_firstFound"/>
49+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_key_lastFound"/>
50+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_containsFound"/>
51+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_starts_withFound"/>
52+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_ends_withFound"/>
4353

4454
<!--
4555
Contained in /wp-includes/spl-autoload-compat.php.

Test/WPTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,11 @@ class ABC implements JsonSerializable {}
2525

2626
$a = mysql_to_rfc3339();
2727

28+
if (array_key_first($array)
29+
|| array_key_last($array)) {}
30+
31+
$a = str_contains($haystack, $needle);
32+
$a = str_starts_with( $haystack, $needle );
33+
$a = str_ends_with( $haystack, $needle );
34+
2835
echo IMAGETYPE_WEBP, IMG_WEBP;

0 commit comments

Comments
 (0)