Creation of dynamic property ThemeSwitcher::$user_id is deprecated

Created on 3 May 2024, about 2 months ago

Problem/Motivation

The current module will trigger deprecation message in PHP 8.2. The creation of dynamic property will probably be deprecated in PHP 9 and hence no longer usable. The error message:

Deprecated function: Creation of dynamic property Drupal\theme_per_user\Theme\ThemeSwitcher::$user_id is deprecated in Drupal\theme_per_user\Theme\ThemeSwitcher->applies() (line 90 of modules/contrib/theme_per_user/src/Theme/ThemeSwitcher.php).

Steps to reproduce

Install the module to a Drupal 10+ under PHP 8.2.

Proposed resolution

Use local variable "$user_id" instead of "$this->user_id" in the "ThemeSwitcher::applies()" function.

Reason:

  • Can't seems to find any other usage of that variable outside of the function.
  • Also, subclass of ThemeSwitcher can easily gain access to user id by "$this->currentUser->id()".

Remaining tasks

Coding and review.

User interface changes

None.

API changes

Probably none. Did not find any usage of ThemeSwitcher from outside

Data model changes

None.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡­πŸ‡°Hong Kong yookoala

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024