Deprecated function: Return type of Drupal\google_analytics\Component\Render\GoogleAnalyticsJavaScriptSnippet::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize():

Created on 28 September 2022, about 2 years ago
Updated 6 July 2023, over 1 year ago

Problem/Motivation

Using Google Analytics with 8.x-3.1 branch generated php errors:

Deprecated function: Return type of Drupal\google_analytics\Component\Render\GoogleAnalyticsJavaScriptSnippet::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include() (line 10 of modules/contrib/google_analytics/src/Component/Render/GoogleAnalyticsJavaScriptSnippet.php).

There is already a resolved issue for the 4.x branch, but this should be applied to users using the 3.x branch.

Steps to reproduce

Use Google analytics 3.x branch with php 8.x
Check the error log for errors

Proposed resolution

@fabiansierra5191 has generated a patch which is based on the fix in this issue: #3258588

Here is a link to his initial patch file:
https://www.drupal.org/files/issues/2022-09-26/google_analytics-deprecat... β†’

Remaining tasks

Review the patch and apply to 3.x branch

πŸ› Bug report
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wylbur Minneapolis, Minnesota, USA

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024