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

Issue fork drupal-3368250

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Tom Grootjans created an issue. See original summary.

tom grootjans’s picture

borisson_’s picture

Status: Needs review » Needs work

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

borisson_’s picture

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

cilefen’s picture

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

sakthi_dev made their first commit to this issue’s fork.

mile23’s picture

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... :-))

Also in just a generic usage:

Deprecated: Creation of dynamic property Drupal\Core\TypedData\TypedData@anonymous::$value is deprecated in /var/www/html/docroot/core/lib/Drupal/Core/TypedData/TypedData.php on line 102

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...

mile23’s picture

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

2) Re: #4: Very strange... Here's a test: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/tests/Drupal/... but there's no ignore regex related to dynamic properties in any of the branches 10.0.x to 11.x.

nagender16’s picture

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

ni.pineau@gmail.com’s picture

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

[EDIT] stupid proposal please ignore, I appologize

Try this patch instead

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

aarantes’s picture

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...

smitghelani’s picture

Version: 11.x-dev » 10.2.x-dev
StatusFileSize
new475 bytes

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,

bramdriesen’s picture

Version: 10.2.x-dev » 11.x-dev

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.

Liam Morland made their first commit to this issue’s fork.

liam morland’s picture

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 permanent solution since it is really just hiding the problem. This could be a temporary solution, perhaps just for Drupal 10, to allow sites to work on PHP 8.2 while a follow-up issue produces a permanent solution.

changfengqj’s picture

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).

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

bramdriesen’s picture

Status: Needs work » Needs review

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.

bramdriesen’s picture

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

smustgrave’s picture

Status: Needs review » Needs work

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

bramdriesen’s picture

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

smustgrave’s picture

What happened when you reran them?

bramdriesen’s picture

Test output looks pretty much identical.

samitk’s picture

Hi @smustgrave, @BramDriesen,

One issue that i noticed, 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.

andypost’s picture

divya.lakshman’s picture

After applying Patch #13 I still see this on watchdog

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 t/modules/contrib/tablefield/src/Plugin/Field/FieldFormatter/TablefieldFormatter.php)

I am on PHP8.3 and Drupal 10.4.1

randalv’s picture

With the current MR changes, I run into a plethora of issues where the value is set to an empty array or null or something...
Not sure why this happens.

Causes issues on basically any entity form for me, for example when saving a new taxonomy term, then the 'weight' value is set to null and gives a WSOD.

niranjan_panem’s picture

Checked the tablefield module web page below link
https://www.drupal.org/project/tablefield/releases/3.0.0-beta1

has the patch from below issue link
https://www.drupal.org/i/3397688

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.