0

I am working on a library and I have "other" libraries it uses that get included via composer. So in one of my libraries I need to use Buzz so I have

<?php

namespace mynamespace;

use Buzz\Browser,
    Buzz\Client\Client;

class Stuff
{
    public function stuff()
    {
        $stuff = new Browser(new Curl());
    }
}

Buzz is https://github.com/kriswallsmith/Buzz

But I am getting an error

Class 'mynamespace\Curl' not found

Now I don't seem to grasp why new Browser(new Curl()); is not referencing the Buzz\Browser. If I change it to new \Buzz\Browser(new Buzz\Client\Client()); it works fine. I checked composer, it is all fine and including stuff correctly.

2 Answers 2

1

Now I don't seem to grasp why new Browser(new Curl()); is not referencing the Buzz\Browser

It is. The class Curl is not defined in your namespace, you'd need another use statement to import Buzz\Client\Curl.

<?php
namespace mynamespace;

use Buzz\Browser,
    Buzz\Client\Curl;

class Stuff
{
    public function stuff()
    {
        $stuff = new Browser(new Curl());
    }
}

Or if Curl is a class in the root namespace you can precede it with a backslash and remove the import statement.

<?php
namespace mynamespace;

use Buzz\Browser;

class Stuff
{
    public function stuff()
    {
        $stuff = new Browser(new \Curl());
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

lol +_+ this is what I get for coding on a weekend, my brain is apparently dead. Thanks!
0

The message doesn't say it can't find Buzz\Browser. It actually does find it. The message says it cannot find mynamespace\Curl - this is because Curl resides in the top level namespace and not in mynamespace.

Solution:

  • either add use Curl; to the use list, or
  • use the backslash when instantiating: new \Curl()

HTH

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.