Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 fwrite(): Passing null to parameter #2 ($data) of type string is deprecated in Masterminds\HTML5\Serializer\OutputRules->wr() #254

Open
jkamizato opened this issue Sep 6, 2024 · 3 comments

Comments

@jkamizato
Copy link

This is an error that shows up, using Drupal.

In that case, this method is called: Html::serialize($dom); , but $dom->nodeValue is null, and its causing the error.

Propose a solution: upcasting fwrite function with string:

    /**
     * Write to the output.
     *
     * @param string $text The string to put into the output
     *
     * @return $this
     */
    protected function wr($text)
    {
        fwrite($this->out, (string) $text);

        return $this;
    }

@ohader
Copy link
Contributor

ohader commented Sep 9, 2024

Thanks for your report. Can you please provide a stack-trace that is leading up to this error? Thx!

@Tregonia
Copy link

I am also encountering this issue in Drupal. This is triggered when setting Trimmed limit: 550 characters to the Summary or trimmed of the body field in a node display,

Drupal Version: 10.2.7
PHP Version: 8.1.29

Here is the stack trace:

Deprecated function: fwrite(): Passing null to parameter #2 ($data) of type string is deprecated in Masterminds\HTML5\Serializer\OutputRules->wr() (line 451 of /home/ide/project/vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php).
Masterminds\HTML5\Serializer\OutputRules->wr(NULL) (Line: 308)
Masterminds\HTML5\Serializer\OutputRules->namespaceAttrs(Object) (Line: 326)
Masterminds\HTML5\Serializer\OutputRules->openTag(Object) (Line: 229)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 122)
Masterminds\HTML5\Serializer\Traverser->children(Object) (Line: 241)
Masterminds\HTML5\Serializer\OutputRules->element(Object) (Line: 93)
Masterminds\HTML5\Serializer\Traverser->node(Object) (Line: 77)
Masterminds\HTML5\Serializer\Traverser->walk() (Line: 319)
Drupal\Component\Utility\Html::serialize(Object) (Line: 258)
Drupal\Component\Utility\Html::normalize('
REDACTED
') (Line: 25)
Drupal\filter\Plugin\Filter\FilterHtmlCorrector->process('
REDACTED
', 'und') (Line: 118)
Drupal\filter\Element\ProcessedText::preRenderText(Array)
call_user_func_array(Array, Array) (Line: 111)
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: 859)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 421)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 125)
__TwigTemplate_fcad470fa4233122af416288d028227d->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 56)
__TwigTemplate_184dc6b5d4c992e0d8dbfc0de219c348->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('REDACTED/themes/custom/REDACTED/templates/field/field.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('field', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 266)
__TwigTemplate_56c4f556221d1328ab3c9466e3243bae___38191478->block_main(Array, Array) (Line: 171)
Twig\Template->displayBlock('main', Array, Array) (Line: 104)
__TwigTemplate_b1b3a8183820adf16dc64dee09387b6a->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array, Array) (Line: 216)
__TwigTemplate_56c4f556221d1328ab3c9466e3243bae___38191478->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 43)
__TwigTemplate_56c4f556221d1328ab3c9466e3243bae->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('REDACTED/themes/custom/REDACTED/templates/content/node.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('node', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 73)
__TwigTemplate_77f21acad24f3f954ddf379229baf499->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('core/modules/views/templates/views-view-list.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('views_view_list', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array) (Line: 475)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 140)
__TwigTemplate_beb756bff590a6c8b103ffa703e86c4b->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 56)
__TwigTemplate_fea8893c3a0dc0e19734e7d5a45223ba->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array) (Line: 38)
Twig\TemplateWrapper->render(Array) (Line: 39)
twig_render_template('REDACTED/themes/custom/REDACTED/templates/views/views-view.html.twig', Array) (Line: 348)
Drupal\Core\Theme\ThemeManager->render('views_view', Array) (Line: 480)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 493)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
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: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
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: 272)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 130)
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)

@Tregonia
Copy link

On further debugging, found some copypasta from a Microsoft source into CKEditor.

In my instance, non-standard elements were found in the source. Specifically, these elements wrapping images:

<w:wrap type="square"></w:wrap>
<wrap type="square" xmlns:w=""></wrap>

Editing the content, and removing the non-standard HTML, resolved this issue for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants