Skip to content

Commit 3b95d2c

Browse files
committed
WP 6.5/6.8/6.9: account for new function and constant polyfills
I checked the WordPress src/wp-includes/compat.php file for new polyfills that should be added and here is what I found that was missing in this repository: WP 6.5 added polyfills for: * `IMAGETYPE_AVIF` and `IMG_AVIF` constants, which were introduced in PHP 8.1. WP 6.8 added polyfills for: * `array_find()`, `array_find_key()`, `array_any()` and `array_all()`, which were introduced in PHP 8.4. WP 6.9 added polyfills for: * `array_first()` and `array_last()`, which were introduced in PHP 8.5. * `IMAGETYPE_HEIF` constant, which was introduced in PHP 8.5. Note: The `IMAGETYPE_AVIF` and `IMAGETYPE_HEIF` constants are not yet flagged by PHPCompatibility. Since excluding error codes that don't exist yet doesn't trigger errors in PHPCS, we may as well add the exclusions proactively. Unless I'm missing something, I believe PHPCompatibility should be updated to check for these constants. Note: WP 6.9 also added polyfills for `utf8_encode()` and `utf8_decode()`, which were deprecated in PHP 8.2 and will be removed in PHP 9.0. These are intentionally not excluded here, as these functions are deprecated and developers should migrate to `mb_convert_encoding()`. My understanding is that the WordPress polyfill exists for backward compatibility with legacy code, but PHPCompatibility should still warn about their usage.
1 parent 6f578a3 commit 3b95d2c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

PHPCompatibilityWP/ruleset.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
* str_starts_with(): since WP 5.9.0
3737
* str_ends_with(): since WP 5.9.0
3838
* array_is_list(): since WP 6.5.0
39+
* IMAGETYPE_AVIF and IMG_AVIF: since WP 6.5.0
40+
* array_find(): since WP 6.8.0
41+
* array_find_key(): since WP 6.8.0
42+
* array_any(): since WP 6.8.0
43+
* array_all(): since WP 6.8.0
44+
* array_first(): since WP 6.9.0
45+
* array_last(): since WP 6.9.0
46+
* IMAGETYPE_HEIF: since WP 6.9.0
3947
-->
4048
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.hash_hmacFound"/>
4149
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_encodeFound"/>
@@ -55,6 +63,15 @@
5563
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_starts_withFound"/>
5664
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.str_ends_withFound"/>
5765
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_is_listFound"/>
66+
<exclude name="PHPCompatibility.Constants.NewConstants.imagetype_avifFound"/>
67+
<exclude name="PHPCompatibility.Constants.NewConstants.img_avifFound"/>
68+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_findFound"/>
69+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_find_keyFound"/>
70+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_anyFound"/>
71+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_allFound"/>
72+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_firstFound"/>
73+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_lastFound"/>
74+
<exclude name="PHPCompatibility.Constants.NewConstants.imagetype_heifFound"/>
5875

5976
<!--
6077
Contained in /wp-includes/spl-autoload-compat.php.

Test/WPTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ class ABC implements JsonSerializable {}
3535
echo IMAGETYPE_WEBP, IMG_WEBP;
3636

3737
if (array_is_list($array)) {}
38+
39+
echo IMAGETYPE_AVIF, IMG_AVIF;
40+
41+
$first_match = array_find( $array, $callback );
42+
$first_match_key = array_find_key( $array, $callback );
43+
if ( array_any( $array, $callback ) ) {}
44+
if ( array_all( $array, $callback ) ) {}
45+
46+
$first_element = array_first( $array );
47+
$last_element = array_last( $array );
48+
49+
echo IMAGETYPE_HEIF;

0 commit comments

Comments
 (0)