- ๐บ๐ธUnited States fathershawn New York
We just saw this after moving to 8.1. As I understand it, this will break in a future version of php and the fix in the patch is a correct and reasonable way to provide the correct type to the core function. Moving this to "needs review" and hoping we can move this to RTBC
- Status changed to Needs work
over 1 year ago 10:11pm 5 April 2023 - ๐บ๐ธUnited States smustgrave
From reading the comments this seems like this can be caused by contrib modules using the wrong code.
If we were to add this having test coverage would be good.
- ๐บ๐ธUnited States fathershawn New York
I'm willing to add a test, but what would the test case be?
I think the proposed fix, a single line change, is a reasonable and least disruptive change:
$text = $element['#text'] ?? ''
Other solutions that occur to me are to cast
$element['#text']
to string explicitly, but we haven't been having problems with passing non-strings in general as that would likely throw an exception when the non-string was passed to str_replace(). - ๐จ๐ฆCanada joseph.olstad
The patch works however I found a way to avoid using the patch.
In our case, the problem came from our custom theme code, in the exception message I saw near the top of the exception the hint: mymodule_preprocess_ds_1col
Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Html::cleanCssIdentifier() (line 107 of core/lib/Drupal/Component/Utility/Html.php). Drupal\Component\Utility\Html::cleanCssIdentifier(NULL) (Line: 23) mymodule_preprocess_ds_1col(Array, 'ds_1col', Array)
From there, I grepped (searched) through our custom code and I found the mymodule_preprocess_ds_1col function and in that function we were not validating for a null parameter
so I fixed the code as follows:
diff --git a/docroot/themes/custom/rmytheme/includes/content.inc b/docroot/themes/custom/mytheme/includes/content.inc index ed348eb9aa..c625023421 100644 --- a/docroot/themes/custom/mytheme/includes/content.inc +++ b/docroot/themes/custom/mytheme/includes/content.inc @@ -20,7 +20,12 @@ function mytheme_preprocess_ds_1col(&$variables) { $niveau_entity = $niveau_entity->getTranslation($lang_code); } $niveau = $niveau_entity->description->value; - $classname = 'alerte-niveau-'.mb_strtolower(HTML::cleanCssIdentifier($niveau)); + if (empty($niveau)) { + $classname = 'alerte-niveau-'; + } + else { + $classname = 'alerte-niveau-'.mb_strtolower(HTML::cleanCssIdentifier($niveau)); + } $variables['attributes']['class'][] = $classname; $variables['niveau'] = $niveau; }
Hope this helps someone else.
- Status changed to Needs review
over 1 year ago 9:44am 7 June 2023 - last update
over 1 year ago 29,420 pass - last update
over 1 year ago 29,412 pass, 1 fail - ๐ช๐ธSpain plopesc Valladolid
This is still an issue in 11.x.
Even if this deprecation message is only triggered by contrib/custom code, I agree that core could be more defensive here.
Attaching new version of the patch including basic test coverage.
The last submitted patch, 22: 3294680-22-test-only.patch, failed testing. View results โ
- Status changed to RTBC
over 1 year ago 9:46pm 7 June 2023 - ๐บ๐ธUnited States smustgrave
Lets see what the committers think.
Thanks for the test case definitely helps this potentially getting in.
- last update
over 1 year ago 29,436 pass - last update
over 1 year ago 29,437 pass - last update
over 1 year ago 29,444 pass - last update
over 1 year ago 29,450 pass - last update
over 1 year ago 29,499 pass - Open on Drupal.org โEnvironment: PHP 8.2 & MySQL 8last update
over 1 year ago Waiting for branch to pass - last update
over 1 year ago 29,508 pass - last update
over 1 year ago 29,553 pass - last update
over 1 year ago 29,553 pass 40:28 36:13 Running- last update
over 1 year ago 29,567 pass - last update
over 1 year ago 29,571 pass - last update
over 1 year ago 29,801 pass - last update
over 1 year ago 29,801 pass - last update
over 1 year ago 29,802 pass - last update
over 1 year ago 29,804 pass - last update
over 1 year ago 29,811 pass - last update
over 1 year ago 29,814 pass - last update
over 1 year ago 29,815 pass - last update
over 1 year ago 29,815 pass 55:29 15:12 Running24:38 21:54 RunningThe last submitted patch, 22: 3294680-22.patch, failed testing. View results โ
- Status changed to Needs work
over 1 year ago 6:03pm 9 August 2023 I believe the Rules module is the reason I am getting this error as well see the details here: https://www.drupal.org/project/rules/issues/3285721#comment-15186484 โจ Unable to get variable 'user' Needs review ;
Because a patch was not available there I was able to resolve the issue by adding the patch marcoscano provided in comment #2 ( https://www.drupal.org/project/drupal/issues/3294680#comment-14597409 ๐ PHP8.1 deprecation: str_replace(): Passing null to parameter #3 Needs work )
- ๐บ๐ธUnited States laura.gates
I patched #2 with drupal 10.1.3 and I so far haven't come across this error message in my logs.
- last update
about 1 year ago 30,168 pass - ๐ซ๐ทFrance nicolas bouteille
Patch #2 solves it for me when using Twig Tweaks filter {{ $some_value | check_markup('restricted_html') }} if $some_value is null.
Thanks! - Status changed to RTBC
12 months ago 2:56pm 21 November 2023 - ๐ฉ๐ชGermany sanduhrs ๐ช๐บ Heidelberg, Germany, Europe
Patch is working and looks reasonable to me.
- last update
12 months ago 30,605 pass - last update
12 months ago 30,634 pass - last update
12 months ago 30,675 pass - last update
12 months ago 30,678 pass - Status changed to Needs work
12 months ago 6:01pm 29 November 2023 The Needs Review Queue Bot โ tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request โ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
- ๐บ๐ฆUkraine Ruslan Piskarov Kiev, Ukraine
Ruslan Piskarov โ made their first commit to this issueโs fork.
- ๐บ๐ฆUkraine Ruslan Piskarov Kiev, Ukraine
I can't create new branch for 11.x-dev.
- First commit to issue fork.
- Merge request !5893Issue #3294680 by plopesc, marcoscano, makkus183: PHP8.1 deprecation:... โ (Open) created by sudishth
- Status changed to Needs review
11 months ago 10:33am 20 December 2023 - Status changed to Needs work
11 months ago 2:28pm 20 December 2023 - ๐บ๐ธUnited States smustgrave
Just fyi #22 still cleanly applied
haven't really tracked down how NULL gets in there in my scenario, but I wonder if just defaulting to an empty string could make sense here.
Going off the issue summary this needs to be answered.
I see the same error.
Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\file\Plugin\Field\FieldType\FileItem->fieldSettingsForm() (line 177 of core/modules/file/src/Plugin/Field/FieldType/FileItem.php). Drupal\file\Plugin\Field\FieldType\FileItem->fieldSettingsForm(Array, Object) (Line: 207) Drupal\image\Plugin\Field\FieldType\ImageItem->fieldSettingsForm(Array, Object) (Line: 219) Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object) (Line: 107) Drupal\Core\Entity\EntityForm->buildForm(Array, Object) call_user_func_array(Array, Array) (Line: 536) Drupal\Core\Form\FormBuilder->retrieveForm('field_config_edit_form', Object) (Line: 283) Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73) Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39) Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->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: 124) 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: 106) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->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)
- Status changed to Needs review
6 months ago 11:56am 10 May 2024 - Status changed to Needs work
6 months ago 12:19pm 10 May 2024 - ๐บ๐ธUnited States smustgrave
Can the question in the proposed solution be answered please.
- last update
6 months ago 29,689 pass - ๐ฎ๐ณIndia amitrawat056
I encountered the same issue. #38 works for me, Drupal 10.2.6.
- ๐ช๐ธSpain plopesc Valladolid
Added steps to reproduce and MR is still valid. Moving to NR
The Needs Review Queue Bot โ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide โ to find step-by-step guides for working with issues.
- ๐ช๐ธSpain plopesc Valladolid
MR is back to green after merging 11.x again.
- ๐บ๐ธUnited States smustgrave
smustgrave โ changed the visibility of the branch 3294680-php8.1-deprecation-strreplace to hidden.
- ๐บ๐ธUnited States smustgrave
smustgrave โ changed the visibility of the branch 3294680-D10.1-php8.1-deprecation-strreplace to hidden.
- ๐บ๐ธUnited States smustgrave
Hiding patches as fix is in MR.
Ran test-only feature
1) /builds/issue/drupal-3294680/core/modules/filter/src/Element/ProcessedText.php:106 str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated Triggered by: * Drupal\Tests\filter\Kernel\FilterAPITest::testProcessedTextElement /builds/issue/drupal-3294680/core/modules/filter/tests/src/Kernel/FilterAPITest.php:250 OK, but there were issues! Tests: 8, Assertions: 79, Deprecations: 1.
Not sure if something should be done to address '#text' => NULL, being allowed but current solution does fix the problem.