question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecated PHP Errors on Site Kit with PHP 8.1

See original GitHub issue

Bug 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 deprecated
  • filter_input(): Passing null to parameter #4 ($options) of type array|int is deprecated
  • strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
  • str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
  • rtrim(): Passing null to parameter #1 ($string) of type string is deprecated
  • Constant FILTER_SANITIZE_STRING is deprecated

image.png

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 by htmlspecialchars.
  • Update the use of filter_input function to set the options parameter to an empty string in case it’s null.
  • Update the use of strtotime and stripos functions to have their parameters as an empty string in case it’s null.
  • 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.
    • Exception: error related to strpos and str_replace will be fixed on #5998
    • rtrip related errors are actually coming from core and we can’t fix them here. See this comment.

Changelog entry

  • Prevent various deprecated PHP Errors on Site Kit with PHP 8.1.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
eugene-manuilovcommented, Oct 12, 2022

It appears that we intentionally call add_submenu_page with null as parent slug to hide it from the Sidebar menu (ie. User Input Page) while still registering the page. It’s a well known hack to achieve the goal. There’s other way to do it, however I’m not sure if it is better solved here or in a separate issue. Any advise?

@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?

The rtrim errors are also from the load_script_textdomain function and I don’t think we can fix it here as we’re not doing anything silly here.

Ok, just leave a comment about it in your PR.

0reactions
mohitwpcommented, Dec 21, 2022

QA Update ✅

image

image

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found