preg_match_all() Error After Upgrading to PHP 8.1

Created on 29 March 2023, almost 2 years ago
Updated 12 July 2023, over 1 year ago

Problem/Motivation

PHP TypeError started to occur after upgrading to PHP 8.1

Steps to reproduce

After creating and saving a node with a text field that uses the SpamSpan filter, I get the following error:

The website encountered an unexpected error. Please try again later.
TypeError: preg_match_all(): Argument #2 ($subject) must be of type string, array given in preg_match_all() (line 71 of modules/contrib/spamspan/src/Plugin/Filter/FilterSpamspan.php).
preg_match_all('/data\:(?:.+?)base64(?:.+?)(?=["|'])/', Array, Array) (Line: 71)
Drupal\spamspan\Plugin\Filter\FilterSpamspan->process(Array, '') (Line: 118)
Drupal\filter\Element\ProcessedText::preRenderText(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 374)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 479)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 79)
__TwigTemplate_2104d5318c962fda708e196342eee14e->doDisplay(Array, Array) (Line: 405)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 378)
Twig\Template->display(Array) (Line: 390)
Twig\Template->render(Array) (Line: 55)
twig_render_template('themes/custom/theme_name/templates/node/node--marketing-landing-page--full.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 433)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 57)
Drupal\advban\AdvbanMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->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: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: cannot reproduce

Version

3.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @mvnovick
  • Assigned to Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    This is indeed important to fix! @Grevil could you take a look?

  • 🇮🇳India ayush.pandey

    Seems that it is not reproducible. I have swithed to the PHP version 8.1 and used SpamSpan module version 8.x-1.3.
    Created a new content type with a field that uses SpamSpan filter on display. Adding content to it saves the node without any issues. Please verify if this happens with any other procedures you use for the issue occurring.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @ayush.pandey so let's try the same with 3.x to be sure this can be closed?

  • 🇩🇪Germany Anybody Porta Westfalica

    I can't imagine this is still existing, but please test with PHP 8.1 @Grevil before the next release.
    Please check the code line and its condition above.

  • Status changed to Closed: cannot reproduce over 1 year ago
  • 🇩🇪Germany Grevil

    Nope, couldn't recreate this issue using

    • PHP 8.2.3
    • Drupal 10.1.1
  • Issue was unassigned.
Production build 0.71.5 2024