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

Issue fork amp-3377128

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alena_stanul created an issue. See original summary.

alena_stanul’s picture

Title: Deprecated function: preg_match_all/strip_tags/substr/strip_tagsPassing null to parameter of type string is deprecated » PHP 8.1 warnings. Passing null to parameter of type string is deprecated

alena_stanul’s picture

Issue summary: View changes
alena_stanul’s picture

Status: Active » Needs review