From e5f110bd28b084965d951949f92a96e7bd44a5d8 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Mon, 2 Mar 2026 15:08:44 +0100 Subject: [PATCH] AI: Remove dead polyfills.php from php-ai-client. Trac ticket: https://core.trac.wordpress.org/ticket/64591 The file is never loaded because the generated autoloader only handles class autoloading, and the four polyfilled functions (`array_is_list`, `str_starts_with`, `str_contains`, `str_ends_with`) are already provided by WordPress Core in `wp-includes/compat.php`. Also updates `installer.sh` to strip the file during future library updates. Co-Authored-By: Claude Opus 4.6 --- .../php-ai-client/src/polyfills.php | 91 ------------------- tools/php-ai-client/installer.sh | 3 + 2 files changed, 3 insertions(+), 91 deletions(-) delete mode 100644 src/wp-includes/php-ai-client/src/polyfills.php diff --git a/src/wp-includes/php-ai-client/src/polyfills.php b/src/wp-includes/php-ai-client/src/polyfills.php deleted file mode 100644 index 20bb0fede1c0b..0000000000000 --- a/src/wp-includes/php-ai-client/src/polyfills.php +++ /dev/null @@ -1,91 +0,0 @@ - $array The array to check. - * @return bool True if the array is a list, false otherwise. - */ - function array_is_list(array $array): bool - { - if ($array === []) { - return \true; - } - $expectedKey = 0; - foreach (\array_keys($array) as $key) { - if ($key !== $expectedKey) { - return \false; - } - $expectedKey++; - } - return \true; - } -} -if (!\function_exists('str_starts_with') && !\function_exists('WordPress\AiClientDependencies\str_starts_with')) { - /** - * Checks if a string starts with a given substring. - * - * @since 0.1.0 - * - * @param string $haystack The string to search in. - * @param string $needle The substring to search for. - * @return bool True if $haystack starts with $needle, false otherwise. - */ - function str_starts_with(string $haystack, string $needle): bool - { - if ('' === $needle) { - return \true; - } - return 0 === \strpos($haystack, $needle); - } -} -if (!\function_exists('str_contains') && !\function_exists('WordPress\AiClientDependencies\str_contains')) { - /** - * Checks if a string contains a given substring. - * - * @since 0.1.0 - * - * @param string $haystack The string to search in. - * @param string $needle The substring to search for. - * @return bool True if $haystack contains $needle, false otherwise. - */ - function str_contains(string $haystack, string $needle): bool - { - if ('' === $needle) { - return \true; - } - return \false !== \strpos($haystack, $needle); - } -} -if (!\function_exists('str_ends_with') && !\function_exists('WordPress\AiClientDependencies\str_ends_with')) { - /** - * Checks if a string ends with a given substring. - * - * @since 0.1.0 - * - * @param string $haystack The string to search in. - * @param string $needle The substring to search for. - * @return bool True if $haystack ends with $needle, false otherwise. - */ - function str_ends_with(string $haystack, string $needle): bool - { - if ('' === $haystack) { - return '' === $needle; - } - $len = \strlen($needle); - return \substr($haystack, -$len, $len) === $needle; - } -} diff --git a/tools/php-ai-client/installer.sh b/tools/php-ai-client/installer.sh index 2083689de7bee..8b8da8f5ab958 100755 --- a/tools/php-ai-client/installer.sh +++ b/tools/php-ai-client/installer.sh @@ -225,6 +225,9 @@ for path in "${REMOVE_PATHS[@]}"; do rm -rf "$TARGET_DIR/third-party/$path" done +# Remove polyfills.php — WordPress Core already provides these functions in compat.php. +rm -f "$TARGET_DIR/src/polyfills.php" + # --------------------------------------------------------------------------- # Generate autoload.php # ---------------------------------------------------------------------------