Deprecated function: strpos()

Created on 26 February 2025, about 1 month ago

Problem/Motivation

If a cookie condition is set up and a visitor does not have a cookie set, site owners will see a deprecated function notice:

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\cookie_condition\Plugin\Condition\Cookie->evaluate() (line 146 of modules/contrib/cookie_condition/src/Plugin/Condition/Cookie.php).

This seems to be happening because \Symfony\Component\HttpFoundation\InputBag::get will return NULL by default if the bag doesn't contain the requested item.

Steps to reproduce

  1. Set up a cookie condition
  2. Configure the site to show all errors with backtrace info
  3. Open an anonymous browsing session and see the notice

Proposed resolution

Pass an empty string in for the $default argument on line 146.


- return strpos($cookies->get($cookie_name), $cookie_value) !== false;
+ return strpos($cookies->get($cookie_name, ''), $cookie_value) !== false;

Remaining tasks

  1. Open MR
  2. Review
  3. Merge
  4. Profit

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States luke.leber Pennsylvania

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024