PHP 8.2 deprecation warning

Created on 13 September 2023, over 1 year ago

Problem/Motivation

Deprecated warnings are displayed when using Drupal 10 and PHP 8.2

Deprecated: Creation of dynamic property Drupal\flysystem\FlysystemBridge::$context is deprecated in /opt/drupal/web/core/lib/Drupal/Core/File/FileSystem.php on line 528

Deprecated: Creation of dynamic property Drupal\flysystem\FlysystemBridge::$context is deprecated in /opt/drupal/web/core/lib/Drupal/Core/File/FileSystem.php on line 563

Deprecated: Creation of dynamic property Drupal\flysystem\FlysystemBridge::$context is deprecated in /opt/drupal/web/core/lib/Drupal/Core/File/FileSystem.php on line 97

Steps to reproduce

Use the module on Drupal 10 and PHP 8.2

Proposed resolution

Create a function with __set method.

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @obomevelhomax
  • Patch to test with proposed solution.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    103 pass
  • Status changed to Closed: won't fix over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States lhridley

    Per the warnings you included, this appears to be an issue occuring within Drupal Core, not Flysystem, and should be addressed there.

    FlysystemBridge does not set any variables called "context", nor does the parent class, Twistor\FlysystemStreamWrapper.

  • πŸ‡ΊπŸ‡¦Ukraine blade_ukraine

    That patch also works for my case:
    Deprecated function: Creation of dynamic property Drupal\flysystem\FlysystemBridge::$context is deprecated in Drupal\image\Controller\ImageStyleDownloadController->sourceImageExists() (line 247 of core/modules/image/src/Controller/ImageStyleDownloadController.php).

  • πŸ‡¨πŸ‡¦Canada adam-vessey PE, Canada

    Bit of poking around, looks like this might be actually be an expectation of PHP proper, that a public $context property exists on stream wrapper implementations: https://www.php.net/manual/en/class.streamwrapper.php#streamwrapper.prop...

    It looks like it's been there for a _long_ time (as in, added in PHP 5 days, according to the wayback machine http://web.archive.org/web/20150814000527/http://php.net/manual/en/class... ), and is only being exposed now with the bump to PHP 8.2 being more strict with dynamic properties?

    That said, might make more sense to just define the:

    public $context;
    

    bit, instead of allowing any arbitrary __set(); though, on second though, we subclass Twistor\FlysystemStreamWrapper, which would have the same issue?: https://github.com/twistor/flysystem-stream-wrapper/issues/27

    I threw together https://github.com/twistor/flysystem-stream-wrapper/pull/28 to get try to get it fixed upstream.

  • πŸ‡³πŸ‡ΏNew Zealand Gold 20 minutes in the future

    Thanks for this @adam-vessey.

    The PR is not merged at the point of this post, so for others that land here, I resolved this by adding twistor/flysystem-stream-wrapper via composer and applying the patch on PR-28 via cweagans/composer-patches.

    If this is not yet merged in please comment on the PR if it worked for you.

  • πŸ‡ΊπŸ‡ΈUnited States Kasey_MK

    Thanks for this solution, which did work to remove the error message we were getting with Flysystem as used by search_api_attachments in our case. I haven't needed twistor/flysystem-stream-wrapper before now, so I'm thinking there must be another solution? I don't know how to account for all the different modules that might interact with Flysystem (but that aren't necessarily designed to do so specifically), but in my admitted ignorance it seems like finding a fix here would be preferred.

    In any case, thanks for pointing to twistor/flysystem-stream-wrapper and the patch that adds a public $context property to the stream wrapper, as that does seem to solve the immediate problem.

  • First commit to issue fork.
  • πŸ‡¬πŸ‡§United Kingdom Eli-T Manchester

    I'm reopening this because I think we need to take a pragmatic approach here.

    Without adding $context to the FlysystemBridge class, we will continue to fill our logs up with PHP warnings on PHP 8.2 and later.

    As @adam-vessey says in #6, the best place to fix this is upstream in the twistor/FlysystemStreamWrapper. However, the PR raised on that project has not had any response from the maintainers, and has no commits since 2019. I think it's wise to proceed on the assumption that will never be merged.

    I appreciate we can add twistor/flysystem-stream-wrapper as an explicit package and then patch as outlined by @gold in #7 but that has the drawback that if flysystem is removed from a project later, twistor/flysystem-stream-wrapper has to be manually removed, which could be missed.

    The argument to patch upstream is moot if that patch will never be accepted upstream.

    Therefore I've opened a pull request to to add $context to this module's FlysystemBridge class. Note this is a different solution to the patch in #2, for the reasons discussed in #6.

Production build 0.71.5 2024