<p>At this point, after much playing around it seems to be working (at least on to the next bit of debugging).</p>

<p>To sum up, it was mostly changes to composer.json, followed by 
<code>
composer remove kr37/calendar37
composer require kr37/calendar37</code></p>

<ol>
<li>src/Plugin.php became src/Calendar37.php</li>
<li>Added <code>"class": "kr37\\calendar37\\Calendar37"</code> to the <code>"extra"</code> part of composer.json</li>
<li>Corrected the <code>autoload "psr-4"</code> to <code>"kr37\\calendar37\\": "src/"</code></li>
<li>Made sure that all the names matched up just right.</li>
<li>This error, "<em>because the name is already in use</em>," should really be "<em>because the name doesn't match up</em>."</li>
</ol>

CC BY-SA 4.0
2019-04-23T01:59:23.207Z
Thank you for this! I had no idea what was going wrong!
mcclaskiem
CC BY-SA 3.0
2018-04-11T05:49:59.137Z
2018-04-11T05:49:59.137Z
kr37
<p>I'm trying to port a Craft 2 plugin to Craft 3, and don't seem smart enough to work out the namespaces. I've stripped out everything except what the docs recommend, but keep getting <em>Cannot declare class kr37\Calendar37\Calendar37, because the name is already in use</em>  Thank you in advance for any suggestions.</p>

<p><strong>Folder structure</strong></p>

<p><code>composer.json
src/Plugin.php</code></p>

<p><strong>Plugin.php</strong></p>

<pre><code>namespace kr37\Calendar37;

class Calendar37 extends \craft\base\Plugin
{
    public function init()
    {
        parent::init();

        // Custom initialization code goes here...
    }
}
</code></pre>

<p><strong>composer.json</strong></p>

<p><code>{
  "name": "kr37/calendar37",
  "description": "Event calendar with unrestricted repetition",
  "version": "3.0.18046",
  "type": "craft-plugin",
  "minimum-stability": "dev",
  "require": {
    "craftcms/cms": "^3.0.1"
  },
  "autoload": {
    "psr-4": {
      "kr37\\calendar\\": "src/"
    }
  },
  "support": {
    "email": "???"
  },
  "extra": {
    "handle": "calendar37",
    "name": "Calendar",
    "developer": "???",
    "developerUrl": "???",
    "hasSettings": "true",
    "hasCpSection": "true"
  }
}</code></p>

<plugins><craft3><updating>
Cannot declare class because the name is already in use
# Cannot declare class because the name is already in use

(Asked by: username_0 on 2018-04-10)

I'm trying to port a Craft 2 plugin to Craft 3, and don't seem smart enough to work out the namespaces. I've stripped out everything except what the docs recommend, but keep getting Cannot declare class username_0\Calendar37\Calendar37, because the name is already in use  Thank you in advance for any suggestions.
Folder structure
composer.json
src/Plugin.php
Plugin.php
namespace username_0\Calendar37;

class Calendar37 extends \craft\base\Plugin
{
    public function init()
    {
        parent::init();

        // Custom initialization code goes here...
    }
}

composer.json
{
  "name": "username_0/calendar37",
  "description": "Event calendar with unrestricted repetition",
  "version": "3.0.18046",
  "type": "craft-plugin",
  "minimum-stability": "dev",
  "require": {
    "craftcms/cms": "^3.0.1"
  },
  "autoload": {
    "psr-4": {
      "username_0\\calendar\\": "src/"
    }
  },
  "support": {
    "email": "???"
  },
  "extra": {
    "handle": "calendar37",
    "name": "Calendar",
    "developer": "???",
    "developerUrl": "???",
    "hasSettings": "true",
    "hasCpSection": "true"
  }
}

**Tags:** plugins, craft3, updating


---

## 1 answers

### Answer by username_0 on 2018-04-11. Score: 8 | Accepted answer

At this point, after much playing around it seems to be working (at least on to the next bit of debugging).

To sum up, it was mostly changes to composer.json, followed by
`composer remove username_0/calendar37
composer require username_0/calendar37`

1. src/Plugin.php became src/Calendar37.php
2. Added `"class": "username_0\\calendar37\\Calendar37"` to the `"extra"` part of composer.json
3. Corrected the `autoload "psr-4"` to `"username_0\\calendar37\\": "src/"`
4. Made sure that all the names matched up just right.
5. This error, "*because the name is already in use*," should really be "*because the name doesn't match up*."

> **Comments:**
> **username_1**: Thank you for this! I had no idea what was going wrong!  

---

