Deprecated PHP Errors on Site Kit with PHP 8.1
See original GitHub issueBug Description
On a test site set up on PHP 8.1. When on any Site Kit page, within Query Monitor there are a large number Deprecated PHP Errors. Some are for WordPress Core but most are related to Site Kit. We have completed a QA of Site Kit on this PHP version and no issues appeared in the console or front end.
Creating this ticket so we can look at any of the errors and if they need fixing to avoid issues in the future.
Constant FILTER_SANITIZE_STRING
is deprecatedfilter_input(): Passing null to parameter #4 ($options) of type array|int
is deprecatedstrpos(): Passing null to parameter #1 ($haystack) of type string
is deprecatedstr_replace(): Passing null to parameter #3 ($subject) of type array|string
is deprecatedrtrim(): Passing null to parameter #1 ($string) of type string
is deprecatedConstant FILTER_SANITIZE_STRING
is deprecated
A more comprehensive list of deprecation notices
PHP Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /.../wp-content/plugins/google-site-kit/includes/Core/Admin/Screens.php on line 370
PHP Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /.../wp-content/plugins/google-site-kit/includes/Core/Admin/Standalone.php on line 95
PHP Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /.../wp-content/plugins/google-site-kit/includes/Core/Assets/Assets.php on line 838
PHP Deprecated: Constant FILTER_SANITIZE_STRING is deprecated in /.../wp-content/plugins/google-site-kit/includes/Core/Authentication/Authentication.php on line 306
PHP Deprecated: filter_input(): Passing null to parameter #4 ($options) of type array|int is deprecated in /.../wp-content/plugins/google-site-kit/includes/Core/Util/Input.php on line 64
PHP Deprecated: preg_replace_callback(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/Url.php on line 465
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Collection::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/HasDataTrait.php on line 37
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Collection::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/HasDataTrait.php on line 13
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Collection::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/HasDataTrait.php on line 25
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Collection::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/HasDataTrait.php on line 17
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Collection::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/HasDataTrait.php on line 21
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Collection::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/HasDataTrait.php on line 29
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Ring\Future\CompletedFutureArray::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/ringphp/src/Future/CompletedFutureArray.php on line 30
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Ring\Future\CompletedFutureArray::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/ringphp/src/Future/CompletedFutureArray.php on line 34
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Ring\Future\CompletedFutureArray::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/ringphp/src/Future/CompletedFutureArray.php on line 14
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Ring\Future\CompletedFutureArray::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/ringphp/src/Future/CompletedFutureArray.php on line 18
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Ring\Future\CompletedFutureArray::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/ringphp/src/Future/CompletedFutureArray.php on line 22
PHP Deprecated: Return type of Google\Site_Kit_Dependencies\GuzzleHttp\Ring\Future\CompletedFutureArray::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/ringphp/src/Future/CompletedFutureArray.php on line 26
PHP Deprecated: Return type of Google\Site_Kit\Core\REST_API\Data_Request::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/includes/Core/REST_API/Data_Request.php on line 124
PHP Deprecated: Return type of Google\Site_Kit\Core\REST_API\Data_Request::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/includes/Core/REST_API/Data_Request.php on line 135
PHP Deprecated: Return type of Google\Site_Kit\Core\REST_API\Data_Request::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/includes/Core/REST_API/Data_Request.php on line 149
PHP Deprecated: Return type of Google\Site_Kit\Core\REST_API\Data_Request::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /.../wp-content/plugins/google-site-kit/includes/Core/REST_API/Data_Request.php on line 158
PHP Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /.../wp-content/plugins/google-site-kit/includes/Core/REST_API/REST_Routes.php on line 104
PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /.../wp-content/plugins/google-site-kit/third-party/guzzlehttp/guzzle/src/Url.php on line 39
PHP Deprecated: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in /.../wp-content/plugins/google-site-kit/includes/Modules/Analytics.php on line 587
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- No PHP deprecation notices should be raised from 1st party Site Kit sources (src/tests/etc)
- Any remaining deprecation notices should only be from dependencies which should have new issues opened for upgrading them (assuming a newer, compliant version exists)
- If no newer version exists which is compatible with PHP 8.1, this should be called out in the IB
Implementation Brief
- Replace the use of the
FILTER_SANITIZE_STRING
filter byhtmlspecialchars
. - Update the use of
filter_input
function to set theoptions
parameter to an empty string in case it’snull
. - Update the use of
strtotime
andstripos
functions to have their parameters as an empty string in case it’snull
. - Most of the third party warnings come from Guzzle where we already have a ticket for upgrading it: https://github.com/google/site-kit-wp/issues/1146
Test Coverage
QA Brief
- Install the plugin and query monitor on a site running php 8.1.
- Activate the plugin and observe query monitor toolbar.
- No PHP errors or warnings should be raised from site kit in splash, dashboard, settings etc page.
Changelog entry
- Prevent various deprecated PHP Errors on Site Kit with PHP 8.1.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11
Top Results From Across the Web
PHP Deprecated errors while using PHP 8.1 | WordPress.org
Hi,. I'm using Site Kit by Google Version 1.90.1 – and I want to upgrade to PHP 8.1. while doing so I checked...
Read more >set_error_handler - Manual - PHP
Sets a user function ( callback ) to handle errors in a script. This function can be used for defining your own way...
Read more >Site Kit by Google 1.90.1 - PluginTests.com
A smoke test was performed on 2022-12-22 16:29:14 UTC . Summary. Errors. 304, PHP deprecation warnings. No JavaScript exceptions.
Read more >Need help with Deprecated: Non-static error when update ...
I need to upgrade from PHP 7.4 to 8.1, but when I try I got four "Deprecated: Non-static" errors. I managed to fix...
Read more >How to Prepare Your WordPress Site for PHP 8
Use PHP_CodeSniffer with the PHPCompatibility standard. · Address known PHP Warnings that are PHP Fatal Errors under PHP 8.0. · Create automated ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@kuasha420, yes, i think a separate ticket will be better because we will need to figure out a better way of adding hidden pages. Could you please create a new ticket?
Ok, just leave a comment about it in your PR.
QA Update ✅