Class cannot be found, but it's available in the file, I get: Fatal Error: Uncaught Error: Class 'Blocks\Base\Activation' not found

Class cannot be found, but the declaration is correct. Here is my code:

Info-Wheel.php

if ( file_exists( dirname( __FILE__ ) . /vendor/autoload.php ) ) {
  require_once dirname( __FILE__ ) . /vendor/autoload.php;
}


use Blocks\Base\Activation;
use Blocks\Base\Deactivation;
/**
 * The code that runs during plugin activation
 */
function iw_activate_plugin() {
  Activation::activate();
}
/**
 * The code that runs during plugin deactivation
 */
function iw_deactivate_plugin() {
  Deactivation::deactivate();
}
/**
 * Register Hooks for deactivation and activation
 */
register_activation_hook( __FILE__, iw_activate_plugin );
register_deactivation_hook( __FILE__, iw_deactivate_plugin );
/**
 * If class exists run it
 */
if ( class_exists( Inc\\Init ) ) {
  Blocks\Init::register_services();
}
Activation.php

 /**
  * Remove rewrite rules and then recreate rewrite rules.
  */
 class Activation {
  public static function activate() {
    flush_rewrite_rules(  );
   }
 }

I use composer, so I can use namespaces. Here is an image of my folder structure:

In my opinion, the class Activation should be found and executed, but somehow WordPress can't find it? I have checked the names and copy-pasted them, just to be sure they're the same. I marked line 56 with a double arrow.

Here is the full error message:


Fatal error: Uncaught Error: Class 'Blocks\Base\Activation' not found in D:\Programme\MAMP\htdocs\wordpress\wp-content\plugins\Info-Wheel\Info-Wheel.php:56
Stack trace:
#0 D:\Programme\MAMP\htdocs\wordpress\wp-includes\class-wp-hook.php(287): iw_activate_plugin('')
#1 D:\Programme\MAMP\htdocs\wordpress\wp-includes\class-wp-hook.php(311): WP_Hook-apply_filters('', Array)
#2 D:\Programme\MAMP\htdocs\wordpress\wp-includes\plugin.php(478): WP_Hook-do_action(Array)
#3 D:\Programme\MAMP\htdocs\wordpress\wp-admin\plugins.php(193): do_action('activate_Info-W...')
#4 {main} thrown in D:\Programme\MAMP\htdocs\wordpress\wp-content\plugins\Info-Wheel\Info-Wheel.php on line 56

Edit: Here is a line from the autoloader:

autoload: {
      psr-4: {Blocks\\: ./Blocks}
  }

Topic fatal-error activation plugin-development Wordpress

Category Web


It was a caching problem with composer.

I retroactively changed my composer.json, so I had to open my terminal and run composer dumpautoload to correct the cache.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.