Hello,
I'm trying to develop my first Magento 2 Plugin inside my module.
When trying to compile the code on CLI I get the following error:
Fatal error: Cannot declare class MyVendor\MyModule\Plugin\ThePlugin\ThePluginPlugin , because the name is already in use in /var/www/html/shop/app/code/MyVendor/MyModule/Plugin/ThePlugin/ThePluginPlugin.php on line 5
The code is simple:
<?php
namespace MyVendor\MyModule\Plugin\ThePlugin;
class ThePluginPlugin {
protected $quote;
protected $request;
public function __construct(\Magento\Framework\App\Request\Http $request){
$this->quote = $checkoutSession->getQuote();
$this->request = $request;
}
public function afterNewAccount($subject, $result){
$quote = $result->getQuote();
// do anything
}
}
?>I really tried everything. There are no other files on the server, which could cause the error. I also cleaned the cache, did setup:upgrade. The error occurs when trying to setup:di:compile.
What would you advice me to do? Even searching the internet, I didn't find anything, which could help.
Thank you very much.
If this ever happens to you, check if you have a misspelling somewhere. Even if you don't see it – I didn't notice ever – just type it new from scratch and your problem is solved.
This was painful.
Should I close or delete this post?
Hi @ci2015
Instead of deleting I suggest you to edit your second past and mention what did you miss spell in your initial code.So it will be helpful for the other users.
I misspelled the Namespace or the Classname. So just retype it to avoid that error.