Deprecated creation of dynamic property in TypedData

Created on 21 June 2023, over 1 year ago
Updated 13 August 2024, 4 months ago

Problem/Motivation

The creation of dynamic properties is deprecated in PHP 8.2

Steps to reproduce

Ran into this error when using a TableField field on a fresh install of Drupal 10.0

Deprecated function: Creation of dynamic property Drupal\tablefield\Plugin\Field\FieldFormatter\TablefieldFormatter::$ModuleHandler is deprecated in Drupal\tablefield\Plugin\Field\FieldFormatter\TablefieldFormatter->__construct() (line 57 of modules/contrib/tablefield/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php).

Proposed resolution

Add the property in TypedData.php

Remaining tasks

Needs review

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Typed dataย  โ†’

Last updated 16 days ago

  • Maintained by
  • ๐Ÿ‡ฆ๐Ÿ‡นAustria @fago
Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Tom Grootjans Hoofddorp, The Netherlands

Live updates comments and jobs are added and updated live.
  • PHP 8.2

    The issue particularly affects sites running on PHP version 8.2.0 or later.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @Tom Grootjans
  • last update over 1 year ago
    Custom Commands Failed
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Tom Grootjans Hoofddorp, The Netherlands
  • last update over 1 year ago
    Custom Commands Failed
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    Looks like this means we can update the phpstan baseline file as well

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium borisson_ Mechelen, ๐Ÿ‡ง๐Ÿ‡ช

    I wonder why this wasn't caught by the rest of the test coverage. Does this signal missing coverage as well?

  • These are existing exceptions in PHPStan. If you fix them you have to remove the exceptions from the baseline file.

  • First commit to issue fork.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mile23 Seattle, WA

    I'm seeing this in Drupal 10.1.8 and PHP 8.2.13, running tests on my project, thanks to symfony/phpunit-bridge.

      5x: Creation of dynamic property Drupal\Core\TypedData\TypedData@anonymous::$value is deprecated
        5x in OURTEST::test from OUR\CLASS
    

    (The @anonymous is because our use-case is weird... :-))

    I can't find any reference to 'dynamic property' in core/phpstan-baseline.neon. Maybe I don't understand how it works or I have the wrong file.

    Apparently this issue will make things break in PHP 9.0. I'd add a PHP 9.0 tag but it doesn't seem to exist yet...

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mile23 Seattle, WA

    1) Derp... the ignore file is core/.deprecation-ignore.txt

    2) Re: #4: Yes, I think this signals a coverage issue, because there's no ignore regex related to dynamic properties in any of the branches 10.0.x to 11.x.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nagender16

    This patch is producing below fatal error when applied for 10.2.2 with workflow enabled content edit page.

    drupal10.typeddata-deprecated_dynamic_propert_3368250-1.patch

    Uncaught PHP Exception InvalidArgumentException: "The state '' does not exist in workflow." ... web\core\modules\workflows\src\Plugin\WorkflowTypeBase.php line 155

  • As a temporary workaround, would it make sense to change web/core/lib/Drupal/Core/TypedData/TypedData.php this way (rather than adding value property which produces bug reported in #9) :

    public function getValue() {
        if (!isset($this->value)) {
          return NULL;
        }
    
        return $this->value;
      }
    

    It seems to suppress the warning

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada aarantes

    Hi,

    I had a similar issue to nagender16 (#9)

    When I applied the patch, I was not able to edit any entity of a content type that has a workflow associated to it.

    The full error message I get is as follows:

    The website encountered an unexpected error. Try again later.
    InvalidArgumentException: The state '' does not exist in workflow. in Drupal\workflows\Plugin\WorkflowTypeBase->getState() (line 155 of core/modules/workflows/src/Plugin/WorkflowTypeBase.php).
    Drupal\content_moderation\Plugin\WorkflowType\ContentModeration->getState(NULL) (Line: 366)
    Drupal\content_moderation\EntityTypeInfo->formAlter(Array, Object, 'node_program_intake_edit_form') (Line: 165)
    content_moderation_form_alter(Array, Object, 'node_program_intake_edit_form') (Line: 545)
    Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'node_program_intake_edit_form') (Line: 841)
    Drupal\Core\Form\FormBuilder->prepareForm('node_program_intake_edit_form', Array, Object) (Line: 284)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 270)
    Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 137)
    Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    So, for the sake of trying something different, I made the patch local and tried to define $value as public and private.

    When made public, I got this error:

    Fatal error: Access level to Drupal\Core\TypedData\PrimitiveBase::$value must be public (as in class Drupal\Core\TypedData\TypedData) in /var/www/docroot/core/lib/Drupal/Core/TypedData/PrimitiveBase.php on line 8

    When made it private I didn't get an error...

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia smitghelani Surat, Gujarat

    With Drupal 10.2.3 and PHP version 8.2. I am also getting the same issue while applying the patch mentioned in comment #2. So, for time being i am using this patch to avoid this deprecation error,

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium BramDriesen Belgium ๐Ÿ‡ง๐Ÿ‡ช

    Patch #13 is not a correct fix and should imho not be used. This is just suppressing the warning. It will also only work as of PHP 8.0+. Version needs to be set to the current development branch and be back-ported if needed to lower versions.

    #5 Still needs to be addressed in the MR.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    Liam Morland โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    8 months ago
    Total: 191s
    #165627
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    I have rebased the issue fork onto 11.x, addressed #5, and opened a merge request.

    However, I am also seeing the issue described in #12 on Drupal 10.2.

    The patch in #13 resolves the issue for me, though, like #14, I hesitate to call that the proper solution since it is really just hiding the problem.

  • Pipeline finished with Failed
    8 months ago
    Total: 198s
    #165631
  • Pipeline finished with Failed
    8 months ago
    Total: 691s
    #165636
  • ๐Ÿ‡จ๐Ÿ‡ณChina changfengqj

    thank you to reply.
    but after I patch this file, appear some wrong when save menu link .
    Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'id' cannot be null: UPDATE "menu_link_content_revision" SET "id"=:db_update_placeholder_0, "langcode"=:db_update_placeholder_1, "revision_user"=:db_update_placeholder_2, "revision_created"=:db_update_placeholder_3, "revision_log_message"=:db_update_placeholder_4, "revision_default"=:db_update_placeholder_5 WHERE "revision_id" = :db_condition_placeholder_0; Array ( [:db_update_placeholder_0] => [:db_update_placeholder_1] => en [:db_update_placeholder_2] => [:db_update_placeholder_3] => 1714985311 [:db_update_placeholder_4] => [:db_update_placeholder_5] => 1 [:db_condition_placeholder_0] => 1 ) in Drupal\mysql\Driver\Database\mysql\ExceptionHandler->handleExecutionException() (line 45 of /var/www/utstar_new/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php).

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    samit.310@gmail.com โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    5 months ago
    Total: 179s
    #233013
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium BramDriesen Belgium ๐Ÿ‡ง๐Ÿ‡ช

    I highly doubt all those failing tests are relevant to the changes in the MR. Think we need to re-trigger them, but unsure how.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium BramDriesen Belgium ๐Ÿ‡ง๐Ÿ‡ช

    Ah, I needed push access, that's why I didn't see the replay button. Re-triggered the tests.

  • Pipeline finished with Failed
    5 months ago
    Total: 2721s
    #233019
  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Seems all those tests are legit failures. Also left a small comment on the MR.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium BramDriesen Belgium ๐Ÿ‡ง๐Ÿ‡ช

    I don't see how this can cause MySQL errors, but ok :P

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    What happened when you reran them?

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium BramDriesen Belgium ๐Ÿ‡ง๐Ÿ‡ช

    Test output looks pretty much identical.

  • Pipeline finished with Failed
    5 months ago
    Total: 606s
    #233317
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    Hi @smustgrave, @BramDriesen,

    One issue, I found is that the user is not getting saved in edit mode, getting the error message 'Email field is required.', Also while saving the new user, user is getting created but Email address is not getting saved. The mail column has the null value in DB for that newly created user.

    Thanks
    Samit K.

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost
Production build 0.71.5 2024