<blockquote>
  <p>Is this some kind of namespace issue?</p>
</blockquote>

<p>Yes.  If the class you're trying to instantiate is in a namespace, you'd need to indicate that:</p>

<pre><code>$object = $rest = new \the\library\class\namespace\mail_delivery();
</code></pre>

<p>If it does not use namespaces, it's probably in the global namespace:</p>

<pre><code>$object = $rest = new \mail_delivery();
</code></pre>

<p>If you do it like in your example:</p>

<pre><code>$object = $rest = new mail_delivery();
</code></pre>

<p>Then PHP will assuming it's in the current file's namespace (Craft) and you'll get the error that you see.</p>

CC BY-SA 3.0
2017-04-24T23:35:36.197Z
2017-04-24T23:35:36.197Z
Brad Bell
<p>I have external library handling connection to mail delivery system. Its just php class. How do i include and use this class inside craft plugin controller?</p>

<p>library.php:</p>

<pre><code>class mail_delivery{
    //code
}
</code></pre>

<p>plugin/controllers/controller.php:</p>

<pre><code>namespace Craft;

class controller extends BaseController
{

    public function init()
    {
        require_once 'library.php';
    }

    public function method(){
        $object = $rest = new mail_delivery();
    }
</code></pre>

<p>I get PHP error:</p>

<blockquote>
  <p>( ! ) Fatal error: Class 'Craft\FmRestAPI' not found in
  C:\xampp\htdocs\mmimport\craft\plugins\freshmailintegration\controllers\FreshmailIntegration_EmailController.php
  on line 27</p>
</blockquote>

<p>Is this some kind of namespace issue?</p>

<plugin-development>
External liblary class inside plugin controller
# External liblary class inside plugin controller

(Asked by: username_0 on 2017-04-24)

I have external library handling connection to mail delivery system. Its just php class. How do i include and use this class inside craft plugin controller?
library.php:
class mail_delivery{
    //code
}

plugin/controllers/controller.php:
namespace Craft;

class controller extends BaseController
{

    public function init()
    {
        require_once 'library.php';
    }

    public function method(){
        $object = $rest = new mail_delivery();
    }

I get PHP error:

( ! ) Fatal error: Class 'Craft\FmRestAPI' not found in
  C:\xampp\htdocs\mmimport\craft\plugins\freshmailintegration\controllers\FreshmailIntegration_EmailController.php
  on line 27

Is this some kind of namespace issue?

**Tags:** plugin-development

---

## 1 answers

### Answer by username_1 on 2017-04-24. Score: 0 | Accepted answer

Is this some kind of namespace issue?

Yes.  If the class you're trying to instantiate is in a namespace, you'd need to indicate that:
$object = $rest = new \the\library\class\namespace\mail_delivery();

If it does not use namespaces, it's probably in the global namespace:
$object = $rest = new \mail_delivery();

If you do it like in your example:
$object = $rest = new mail_delivery();

Then PHP will assuming it's in the current file's namespace (Craft) and you'll get the error that you see.


---

