PHP 8.1 warnings. Passing null to parameter of type string is deprecated

Created on 26 July 2023, over 1 year ago
Updated 27 July 2023, over 1 year ago

Problem/Motivation

After switch to php 8.1 some warnings were catched in amp_node_view():

Deprecated function: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in token_scan() (line 118 of .../docroot/includes/token.inc)
Deprecated function: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in amp_node_view() (line 672 of .../modules/contrib/amp/amp.module).
Deprecated function: substr(): Passing null to parameter #1 ($string) of type string is deprecated in amp_node_view() (line 690 of .../modules/contrib/amp/amp.module).
Deprecated function: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in {closure}() (line 739 of .../modules/contrib/amp/amp.module).

Steps to reproduce

1. Enable php8.1.
2. Go to some amp page for any node.
3. Check logs.

Root cause:

The variable 'amp_metadata_options_' . $node->type is not set.

Proposed resolution:

I suggest 2 options:

1) In addition to https://www.drupal.org/project/amp/issues/3198210 🐛 Edit Notice: Trying to access array offset on value of type null on php 7.4 and php8.1 Needs review make null variable conversion to string. Please see https://git.drupalcode.org/project/amp/-/merge_requests/14

2) Do not add AMP metadata for case, when the variable 'amp_metadata_options_' . $node->type is not set. Please see https://git.drupalcode.org/project/amp/-/merge_requests/15

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇧🇾Belarus alena_stanul

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

Production build 0.71.5 2024