Problem/Motivation
I have created a simple view, but it does not work - the php error is thrown on preview and on full page view. Looks like this error comes from views module, but is related to the webprofiler module that is also enabled on my site. A bit weird that this error occurs only for some of my views, while others works fine.
Error: Typed property Drupal\views\ViewExecutable::$build_time must not be accessed before initialization in Drupal\webprofiler\Views\TraceableViewExecutable->getBuildTime() (line 28 of /app/docroot/modules/contrib/webprofiler/src/Views/TraceableViewExecutable.php).
#0 /app/docroot/modules/contrib/webprofiler/src/DataCollector/ViewsDataCollector.php(53): Drupal\webprofiler\Views\TraceableViewExecutable->getBuildTime()
#1 /app/vendor/symfony/http-kernel/Profiler/Profiler.php(169): Drupal\webprofiler\DataCollector\ViewsDataCollector->collect(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Ajax\AjaxResponse), NULL)
#2 /app/docroot/modules/contrib/webprofiler/src/EventListener/ProfilerListener.php(116): Symfony\Component\HttpKernel\Profiler\Profiler->collect(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Ajax\AjaxResponse), NULL)
#3 [internal function]: Drupal\webprofiler\EventListener\ProfilerListener->onKernelResponse(Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response', Object(Drupal\tracer\EventDispatcher\TraceableEventDispatcher))
#4 /app/docroot/modules/contrib/tracer/src/EventDispatcher/TraceableEventDispatcher.php(94): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response', Object(Drupal\tracer\EventDispatcher\TraceableEventDispatcher))
#5 /app/vendor/symfony/http-kernel/HttpKernel.php(214): Drupal\tracer\EventDispatcher\TraceableEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response')
#6 /app/vendor/symfony/http-kernel/HttpKernel.php(202): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Ajax\AjaxResponse), Object(Symfony\Component\HttpFoundation\Request), 1)
#7 /app/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#8 /app/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#9 /app/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#10 /app/docroot/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#11 /app/docroot/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#12 /app/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /app/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /app/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /app/docroot/modules/contrib/tracer/src/StackMiddleware/TracesMiddleware.php(38): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /app/docroot/modules/contrib/webprofiler/src/StackMiddleware/WebprofilerMiddleware.php(40): Drupal\tracer\StackMiddleware\TracesMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /app/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /app/docroot/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /app/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /app/docroot/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /app/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#22 {main}
Steps to reproduce
- Enable views and webprofiler modules.
- Create some view that provides a page with filters.
- Try to preview it. Or try to open a page that it provides.
Proposed resolution
I'd suggest to change the property declaration in ViewExecutable.php from:
public string|float $build_time;
to:
public string|float $build_time = -1; // or maybe 0? Or ''?
Once I've done this on my site - the issue was gone.