MadeOfSport
MadeOfSport

Reputation: 513

Zend Framework 2 | instance of Type

I'm wondering why i get different results while checking this:

The ouput of this:

get_class($request);

"Zend\Console\Request"

First example (output is true):

    use Zend\Console\Request as ConsoleRequest,

    class Module {
        public function test() {

          var_dump($request instanceof ConsoleRequest);
        }
    }

Second Example (output is false):

    class Module {
        public function test() {

          var_dump($request instanceof Zend\Console\Request);
        }
    }

Upvotes: 1

Views: 648

Answers (1)

Carlos
Carlos

Reputation: 5072

In the second case, try with the fully qualified class name:

class Module {
    public function test() {

      var_dump($request instanceof \Zend\Console\Request);
    }
}

Otherwise PHP tries to look into a subnamespace called Zend into your current namespace.

Upvotes: 2

Related Questions