<p>Assuming <code>Plugin1</code> is their main plugin class file name, you could do:</p>
<pre><code>\fully\qualified\namespace\Plugin1::getInstance()-&gt;myService-&gt;myMethod();
</code></pre>
<p>In order for this to work:</p>
<ol>
<li>Craft must be installed.</li>
<li><code>Plugin1</code> must be installed and enabled in Craft.</li>
<li>Composer autoloading has to be working so that it knows where to find <code>Plugin1</code></li>
</ol>
<p>If you're doing this from a custom module, then you'll need to listen for the <code>EVENT_INIT</code> event, because plugins get instantiated after modules.</p>
<p>i.e.</p>
<pre><code>Craft::$app-&gt;on(Application::EVENT_INIT, function() {
    \fully\qualified\namespace\Plugin1::getInstance()-&gt;myService-&gt;myMethod();
});
</code></pre>

CC BY-SA 4.0
2019-02-18T00:52:10.183Z
Thanks Brad, exactly what I was looking for.
Wei
CC BY-SA 4.0
2019-12-13T03:19:03.883Z
Doing this returns null on getInstance() on my end.  Could it be because my plugin class name is called Plugin and I need to name it something else?
biko
CC BY-SA 4.0
2020-01-07T21:06:43.513Z
Did you figure this out biko? I have the same issue.
Darryl Hardin
CC BY-SA 4.0
2020-10-23T17:12:31.197Z
I have the same issue as Biko, i'm losing my mind over this
Kevon
CC BY-SA 4.0
2019-02-16T00:09:20.440Z
2020-12-02T22:00:24.660Z
2020-12-02T22:00:24.660Z
Brad Bell
<p>In Craft 2, we used to be able to do so by doing:</p>

<pre><code>craft()-&gt;plugin1-&gt;myMethod();
</code></pre>

<p>from Plugin 2's service for example.</p>

<p>Now in Craft 3, I couldn't figure out a way to do it.</p>

<pre><code>Plugin1::$plugin-&gt;myService-&gt;myMethod();
</code></pre>

<p>seems to only work within the Plugin 1's code base.</p>

CC BY-SA 4.0
2019-02-15T06:17:21.077Z
It works as well in other plugins if they have a variable called `$plugin` maybe you could tell us the name of the other plugin? Also it's important where you call this method. If it's in your plugins init function chances are high the other plugin is not created at this time
Robin Schambach
<plugin-development><craft3><services>
Craft 3: how to call methods in another plugin's service?
# Craft 3: how to call methods in another plugin's service?

(Asked by: username_0 on 2019-02-14)

In Craft 2, we used to be able to do so by doing:
craft()->plugin1->myMethod();

from Plugin 2's service for example.
Now in Craft 3, I couldn't figure out a way to do it.
Plugin1::$plugin->myService->myMethod();

seems to only work within the Plugin 1's code base.

**Tags:** plugin-development, craft3, services

> **Comments:**
> **username_1**: It works as well in other plugins if they have a variable called `$plugin` maybe you could tell us the name of the other plugin? Also it's important where you call this method. If it's in your plugins init function chances are high the other plugin is not created at this time  

---

## 1 answers

### Answer by username_2 on 2019-02-16. Score: 4 | Accepted answer

Assuming Plugin1 is their main plugin class file name, you could do:
\fully\qualified\namespace\Plugin1::getInstance()->myService->myMethod();

In order for this to work:

Craft must be installed.
Plugin1 must be installed and enabled in Craft.
Composer autoloading has to be working so that it knows where to find Plugin1

If you're doing this from a custom module, then you'll need to listen for the EVENT_INIT event, because plugins get instantiated after modules.
i.e.
Craft::$app->on(Application::EVENT_INIT, function() {
    \fully\qualified\namespace\Plugin1::getInstance()->myService->myMethod();
});

> **Comments:**
> **username_0**: Thanks Brad, exactly what I was looking for.  
> **username_3**: Doing this returns null on getInstance() on my end.  Could it be because my plugin class name is called Plugin and I need to name it something else?  
> **username_4**: Did you figure this out username_3? I have the same issue.  
> **username_5**: I have the same issue as Biko, i'm losing my mind over this  

---

