Deprecated function: Creation of dynamic property is deprecated

Created on 1 August 2024, 5 months ago
Updated 18 September 2024, 3 months ago

Problem/Motivation

On PHP 8.3 I'm getting the following deprecated warning:

Deprecated function: Creation of dynamic property Drupal\views_ical\Plugin\views\style\IcalWizard::$vTimezone is deprecated in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 409 of /modules/contrib/views_ical/src/ViewsIcalHelper.php)

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States j_s

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

Merge Requests

Comments & Activities

  • Issue created by @j_s
  • @joshuasosa,
    I am unable to reproduce the error. Could you please provide steps to reproduce?

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    aaron.ferris β†’ made their first commit to this issue’s fork.

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    Raised an MR that will hopefully resolve this, looking at

       if (!isset($style->vTimezone)) {
          $style->vTimezone = new \Eluceo\iCal\Component\Timezone($tz);
        }
    

    From ViewsIcalHelper I believe the definition is correct.

  • Status changed to Needs review 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris
  • πŸ‡¨πŸ‡·Costa Rica yuvania

    Hi @aaron.ferris ,

    1. I tested the change https://git.drupalcode.org/issue/views_ical-3465114/-/commit/b718fd9d626... where the property vTimezone was added to the style, and it works perfectly. I had considered the same solution, and here's why it makes sense:
    2. Avoiding Deprecated Dynamic Properties: By defining the property explicitly in the class, we prevent PHP 8.3's deprecation warnings about dynamic property creation. This keeps our code future-proof and aligns with best practices.
    3. Logical Association: vTimezone is intrinsically tied to the style's configuration and state. Placing it within the style ensures that all relevant data and behavior are encapsulated within the appropriate object.
    4. Maintaining Functionality: This change preserves the existing functionality and ensures that time zone transitions are correctly managed and applied within the iCal generation.

    Thanks for the merge request! It should help maintain compatibility with newer PHP versions while keeping the module's functionality intact.

  • Status changed to RTBC 5 months ago
  • πŸ‡¨πŸ‡·Costa Rica yuvania
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    You don't need to run this issue through ChatGPT. Just say you tested it, and looks good to you.

    I'll take a look at the patch and merge if it looks good.

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

    This MR now produces an error for me:
    Error: Cannot access protected property Drupal\views_ical\Plugin\views\style\IcalWizard::$vTimezone in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 409 of /modules/contrib/views_ical/src/ViewsIcalHelper.php).

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    Updated the MR, wondering if we want to approach this in a different way.

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

    The updated MR did resolve the warning (thanks!) but it looks like there's more. Not sure how many more there will be.

    Deprecated function: Creation of dynamic property Drupal\views_ical\Plugin\views\style\IcalWizard::$checktransitions is deprecated in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 349 of /modules/contrib/views_ical/src/ViewsIcalHelper.php)

  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States bburg Washington D.C.

    I would prefer to use getters and setters here. I went ahead and pushed a new commit which does that. Also removed a seemingly unnecessary line which was causing the warning joshuasosa pointed out.

    Changing to needs to get some additional confirmation the updated patch works for other folks.

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

    With #13's updated MR I get this whitescreen error:

    TypeError: Drupal\views_ical\Plugin\views\style\IcalWizard::setVTimezone(): Argument #1 ($vTimezone) must be of type Drupal\views_ical\Plugin\views\style\Eluceo\iCal\Component\Timezone, Eluceo\iCal\Component\Timezone given, called in /modules/contrib/views_ical/src/ViewsIcalHelper.php on line 407 in Drupal\views_ical\Plugin\views\style\IcalWizard->setVTimezone() (line 116 of /modules/contrib/views_ical/src/Plugin/views/style/IcalWizard.php).

    If I change $style->setVTimezone(new Timezone($tz)); back to $style->vTimezone = new \Eluceo\iCal\Component\Timezone($tz); it works again.

    The deprecation warning I posted previously seems to nicely be gone.
    The next deprecated warning is given:

    Deprecated function: Creation of dynamic property Drupal\views_ical\Plugin\views\style\IcalWizard::$usedTimezoneTransitions is deprecated in Drupal\views_ical\ViewsIcalHelper->addTimezone() (line 347 of /modules/contrib/views_ical/src/ViewsIcalHelper.php)

Production build 0.71.5 2024