Magento2: Magento 2.1 compile issue: [ReflectionException] Class does not exist

Created on 16 Aug 2016  路  5Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.1 via download
  2. PHP7 / Nginx / varnish / redis

Steps to reproduce

  1. Run php bin/magento setup:di:compile -vvv

Expected result

  1. Compiling end with success

Actual result

  1. Compiling shows this error

[ReflectionException]
Class does not exist

Exception trace:
() at /var/www/html/magento2/vendor/magento/framework/Code/Reader/ClassReader.php:19
ReflectionClass->__construct() at /var/www/html/magento2/vendor/magento/framework/Code/Reader/ClassReader.php:19
Magento\Framework\Code\Reader\ClassReader->getConstructor() at /var/www/html/magento2/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassReaderDecorator.php:35
Magento\Setup\Module\Di\Code\Reader\ClassReaderDecorator->getConstructor() at /var/www/html/magento2/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Area.php:53
Magento\Setup\Module\Di\Code\Reader\Decorator\Area->getList() at /var/www/html/magento2/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php:109
Magento\Setup\Module\Di\App\Task\Operation\Area->getDefinitionsCollection() at /var/www/html/magento2/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php:84
Magento\Setup\Module\Di\App\Task\Operation\Area->doOperation() at /var/www/html/magento2/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php:56
Magento\Setup\Module\Di\App\Task\Manager->process() at /var/www/html/magento2/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php:195
Magento\Setup\Console\Command\DiCompileCommand->execute() at /var/www/html/magento2/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
Symfony\Component\Console\Command\Command->run() at /var/www/html/magento2/vendor/symfony/console/Symfony/Component/Console/Application.php:874
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/magento2/vendor/symfony/console/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at /var/www/html/magento2/vendor/magento/framework/Console/Cli.php:96
Magento\Framework\Console\Cli->doRun() at /var/www/html/magento2/vendor/symfony/console/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /var/www/html/magento2/bin/magento:23

setup:di:compile

This occurred out of the dark today after installing a new extension (m2epro). Also disabling the new extension has no effect.

Is this a bug? How can we debug this any further?

Format is valid

Most helpful comment

We use Redis in our setup. When I receive this error, flushing the Redis cache usually does the trick.
Here's a short help article from Magento regarding the issue.

All 5 comments

We solved this by removing the m2e pro extension form its folder but i think the output should be more specific here showing the extension which causes the problem.

Can verify this...

I had a similar issue:

dev@shopserver:~/magento $ bin/magento setup:di:compile -vvv
Compilation was started.
Area configuration aggregation... 5/7 [====================>-------]  71% 23 secs 244.0 MiB


  [ReflectionException]  
  Class                  
   does not exist        



Exception trace:
 () at /home/dev/magento/vendor/magento/framework/Code/Reader/ClassReader.php:19
 ReflectionClass->__construct() at /home/dev/magento/vendor/magento/framework/Code/Reader/ClassReader.php:19
 Magento\Framework\Code\Reader\ClassReader->getConstructor() at /home/dev/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/ClassReaderDecorator.php:35
 Magento\Setup\Module\Di\Code\Reader\ClassReaderDecorator->getConstructor() at /home/dev/magento/setup/src/Magento/Setup/Module/Di/Code/Reader/Decorator/Area.php:53
 Magento\Setup\Module\Di\Code\Reader\Decorator\Area->getList() at /home/dev/magento/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php:109
 Magento\Setup\Module\Di\App\Task\Operation\Area->getDefinitionsCollection() at /home/dev/magento/setup/src/Magento/Setup/Module/Di/App/Task/Operation/Area.php:84
 Magento\Setup\Module\Di\App\Task\Operation\Area->doOperation() at /home/dev/magento/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php:56
 Magento\Setup\Module\Di\App\Task\Manager->process() at /home/dev/magento/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php:187
 Magento\Setup\Console\Command\DiCompileCommand->execute() at /home/dev/magento/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
 Symfony\Component\Console\Command\Command->run() at /home/dev/magento/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /home/dev/magento/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /home/dev/magento/vendor/magento/framework/Console/Cli.php:96
 Magento\Framework\Console\Cli->doRun() at /home/dev/magento/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /home/dev/magento/bin/magento:23

I my case this was caused by a utility-script that had "class" as keyword in global scope (without defining a class)
minimal file to reproduce (f.e. in an module-dir (vendor/myvendor/mymodule/choke_di_compile_example.php):

<?php
use Magento\Framework\ObjectManager\ObjectManager;

$dummy = ObjectManager::class;

(it doesn't matter which class is used, the important part is using the class-keyword in "::class" instead of "class MyClassName {}")
It works, when the class-keyword is not in the global scope, f.e. by moving it into a class or function, f.e.:

<?php
namespace Foo;

use Magento\Framework\ObjectManager\ObjectManager;

function doIt() {
    $dummy = ObjectManager::class;
}

doIt();

sudo php magento/bin/magento setup:di:compile -vvv
Compilation was started.
Application code generator... 3/7 [============>---------------] 42% 5 secs 168.0 MiB

[ReflectionException]
Class kuber\utility\KuberPaymentTransactionCallback does not exist

Exception trace:
() at /var/www/html/merakuber/magento/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php:177
ReflectionClass->__construct() at /var/www/html/merakuber/magento/setup/src/Magento/Setup/Module/Di/Code/Scanner/PhpScanner.php:177
Magento\Setup\Module\Di\Code\Scanner\PhpScanner->collectEntities() at /var/www/html/merakuber/magento/setup/src/Magento/Setup/Module/Di/App/Task/Operation/ApplicationCodeGenerator.php:77
Magento\Setup\Module\Di\App\Task\Operation\ApplicationCodeGenerator->doOperation() at /var/www/html/merakuber/magento/setup/src/Magento/Setup/Module/Di/App/Task/Manager.php:56
Magento\Setup\Module\Di\App\Task\Manager->process() at /var/www/html/merakuber/magento/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php:206
Magento\Setup\Console\Command\DiCompileCommand->execute() at /var/www/html/merakuber/magento/vendor/symfony/console/Command/Command.php:241
Symfony\Component\Console\Command\Command->run() at /var/www/html/merakuber/magento/vendor/symfony/console/Application.php:843
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/merakuber/magento/vendor/symfony/console/Application.php:193
Symfony\Component\Console\Application->doRun() at /var/www/html/merakuber/magento/vendor/magento/framework/Console/Cli.php:104
Magento\Framework\Console\Cli->doRun() at /var/www/html/merakuber/magento/vendor/symfony/console/Application.php:117
Symfony\Component\Console\Application->run() at /var/www/html/merakuber/magento/bin/magento:23

setup:di:compile
Issue persist and really depressed with issue no sense of error.

We use Redis in our setup. When I receive this error, flushing the Redis cache usually does the trick.
Here's a short help article from Magento regarding the issue.

Was this page helpful?
0 / 5 - 0 ratings