var_export() does not handle circular references

Created on 1 March 2022, over 2 years ago
Updated 27 June 2024, 5 months ago

Problem/Motivation

I have a Drupal 9.3 site with php 7.3. After enabling the render-example module I try to go to the link "Demonstration of render array usage." and I receive an error "502 Proxy Error", in the log messages I have many warnings with the following content:

Warning: var_export does not handle circular references en Drupal\Component\Utility\Variable::export() (lรญnea 88 de /var/www/html/my-site/web/core/lib/Drupal/Component/Utility/Variable.php)
#0 /var/www/html/my-site/web/core/includes/bootstrap.inc(346): _drupal_error_handler_real(2, 'var_export does...', '/var/www/html/m...', 88)
#1 [internal function]: _drupal_error_handler(2, 'var_export does...', '/var/www/html/m...', 88, Array)
#2 /var/www/html/my-site/web/core/lib/Drupal/Component/Utility/Variable.php(88): var_export(Object(Drupal\Core\StringTranslation\TranslatableMarkup), true)
#3 /var/www/html/my-site/web/core/lib/Drupal/Component/Utility/Variable.php(60): Drupal\Component\Utility\Variable::export(Object(Drupal\Core\StringTranslation\TranslatableMarkup), '  ', false)
#4 /var/www/html/my-site/web/modules/contrib/examples/modules/render_example/src/Controller/RenderExampleController.php(407): Drupal\Component\Utility\Variable::export(Array)
#5 [internal function]: Drupal\render_example\Controller\RenderExampleController->arrays()
#6 /var/www/html/my-site/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#7 /var/www/html/my-site/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 /var/www/html/my-site/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#9 /var/www/html/my-site/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#10 /var/www/html/my-site/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /var/www/html/my-site/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#12 /var/www/html/my-site/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /var/www/html/my-site/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /var/www/html/my-site/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /var/www/html/my-site/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/my-site/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/my-site/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /var/www/html/my-site/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /var/www/html/my-site/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/my-site/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#21 {main}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Needs review

Version

4.0

Component

Render Example

Created by

๐Ÿ‡ช๐Ÿ‡ธSpain jmohino

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡จ๐Ÿ‡ณChina jungle Chongqing, China

    You can always use dpm() with the Devel module installed for debugging.

    Would you try it with the latest dev branch 4.0.x (for Drupal core 9.4+) or the latest release 4.0.0 to see if the bug still exists?

    Thanks!

  • yes bug still exist.

    Drupal 10.2.5 + version 4.0.2

    I have Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 534777856 bytes) in /app/web/core/lib/Drupal/Component/Utility/Variable.php on line 88

    with '#markup' => htmlentities(json_encode($build[$key])), no problem

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    I think that what described here explains why adding \Drupal\render_example\Controller\RenderExampleController::preRender() as pre-render callback causes two tests to fails.
    In fact, one of the tests expects to get a 200 status back, but it gets a 500 status. Usually, that is caused by some errors on PHP side, like the one described here.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 5 months ago
    186 pass, 13 fail
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Pipeline finished with Success
    5 months ago
    Total: 179s
    #210109
Production build 0.71.5 2024