Update from 7.0.1 to 7.1.12 - includeWithEvent - The site is currently offline due to encountering an error

Your software
My Mautic version is: 7.0.1 updating to 7.1.2
My PHP version is: 8.4
My Database type and version is: MariaDB 10.11.14
Install method: Composer (mautic/recommended-project), project root at <home>/mautic with docroot/ inside

Your problem
My problem is: after a routine Composer minor update from 7.0.1 to 7.1.2, the whole site went offline (“The site is currently offline due to encountering an error”). Every page, including /s/login, fails to render, so I cannot even log in.

The cause is a return-type mismatch introduced by Twig. During the update, composer update --with-dependencies moved twig/twig from v3.23.0 to v3.28.0. In Twig 3.28, Twig\Extension\CoreExtension::include() can return a Twig\Markup object instead of a plain string (see upstream discussion include() function must return a Markup object instead of a string · Issue #4802 · twigphp/Twig · GitHub ). But Mautic\CoreBundle\Twig\Extension\OverrideIncludeExtension::includeWithEvent() is declared with a : string return type and returns CoreExtension::include(...) directly, so PHP throws a TypeError and breaks rendering of any template that uses the overridden include() — starting with the login/base templates. Both return CoreExtension::include(...) statements in the method (array-handling branch and single-template branch) are affected.

Note: pinning twig/twig back to 3.23.0 is not a clean option, because Composer’s block-insecure audit rejects it (that range is flagged by security advisories), and oneup/uploader-bundle (required by mautic/core-lib 7.1.2) allows ^2.4 || ^3.0, so the resolver lands on a recent Markup-returning Twig anyway. The fix belongs in Mautic’s method signature.

These errors are showing in the log:

mautic.CRITICAL: Uncaught PHP Exception Twig\Error\RuntimeError:
"An exception has been thrown during the rendering of a template
(\"Mautic\CoreBundle\Twig\Extension\OverrideIncludeExtension::includeWithEvent():
Return value must be of type string, Twig\Markup returned\")
in \"@MauticUser/Security/base.html.twig\" at line 12."

[previous exception] TypeError:
Mautic\CoreBundle\Twig\Extension\OverrideIncludeExtension::includeWithEvent():
Return value must be of type string, Twig\Markup returned
at .../docroot/app/bundles/CoreBundle/Twig/Extension/OverrideIncludeExtension.php:65

(The same TypeError also surfaces via @MauticCore/Default/slim.html.twig at line 3.)

Steps I have tried to fix the problem:

  1. Cleared the prod cache (rm -rf var/cache/prod + bin/console cache:clear) — no change, same TypeError.
  2. Tried to pin twig/twig back to 3.23.0 with composer require "twig/twig:3.23.0" — blocked by security advisories (block-insecure) and by the oneup/uploader-bundle constraint. Reverted.
  3. Workaround that fixed it: cast both return CoreExtension::include(...) statements to (string) in app/bundles/CoreBundle/Twig/Extension/OverrideIncludeExtension.php, then cleared cache. Site is fully back. Since Twig\Markup implements __toString(), the rendered HTML is identical.
// before
return CoreExtension::include($env, $context, $templates, $event->getVars(), $withContext, $ignoreMissing, $sandboxed);
// after
return (string) CoreExtension::include($env, $context, $templates, $event->getVars(), $withContext, $ignoreMissing, $sandboxed);

Suggested proper fix: cast to (string) in core, or adjust the declared return type to accept Twig\Markup. On Composer installs this edit is under docroot/app/ and gets overwritten by the next composer update, so it must be reapplied until an official fix ships.

I reported this bug officially at: