I have some functions in another plugin that I'd like to use. For example, I'm using the shortcodes plugin, and it has a function shortcode_atts that I want to use in my plugin.


If the method you want to access is public and in another service file, you could access it via the service layer:


The method you are using above, the Scope Resolution Operator should work fine without declaring the \Craft namespace, as the plugins should already be loaded into the Craft namespace. It's used for accessing static and constant methods:


In cases where you may be loading a library that is not in the Craft namespace, the syntax you're using above would be needed, where you declare the full namespace:

  • Thanks for the in depth answer, Ben! I did see the way you're showing above. However, I actually think using use \Craft\Whatever as Mything below the namespace declaration is a working and clean way of doing it. Then you can just Mything::method()
    – Ryan
    Oct 12 '14 at 16:07
  • Sounds good Ryan. I realize I was using PluginName::method() in my first example instead of the appropriate ClassName::method() (updated above). I agree that when necessary using the use operator below the namespace is cleaner than the full namespace in the code. Oct 12 '14 at 19:53

I did it this way:


Seems directly accessing it via namespace would be correct (assuming!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.