I'm seeing the following error when I enable xhprof in Drupal 8 either via Drush or via Composer.
Class 'Drupal\xhprof\RequestMatcher\XHProfRequestMatcher' not found in /var/www/mysite/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 272
I had xhprof working for a day or so, and randomly started seeing this issue. This feels very much like a Symfony/Composer autoloader issue to me, but I'm struggling with a technique or strategy for fixing or troubleshooting this.
The Call Stack feels pretty useless in this context.
I'm looking for any fix to this issue specifically, but I'm also looking for some technique or strategy for troubleshooting the missing class fatal error. The missing class error seems to keep cropping up for me with Drupal 8. I've tried to trace through the object hierarchy via xdebug, but Drupal 8 and Symfony, have a very abstracted object hierarchy. This makes it nearly impossible to be able to logically backtrack from where the error is thrown.
Why is the class not found, even though the class is definitely here: docroot/modules/contrib/xhprof/src/RequestMatcher/XHProfRequestMatcher.php?
After trying everything I could think of, I decided to just try and rebuild my VM with:
vagrant reload --provision
Sure enough, the fatal error went away. Is there some cache somewhere that drush or Drupal Console wouldn't have access to? Maybe it has something to do with the RAM or OPCACHE as @cilefen mentioned?
Note that I do not have memcache or redis running on this VM. Per a conversation on the Drupal-VM issue queue I may have been able to solve the problem by restarting PHP or just doing a reload without having to do a --provision.