Your example should return true, I think you are testing an interface from another file and you are missing the use A;
in your class C
.
Also you have to use the full namespace to check if your class is an instance of your interface.
If you have an interface like this :
namespace MyNamespace;
Interface A {
public function test();
}
A class B like this :
namespace MyNamespace;
class B implements A {
public function test() {
return $something;
}
And your class C is like this :
namespace MyNamespace\Util;
class C {
// ...
$someBclass = new B();
if ($someClassB instanceof A){
die('InstanceOf');
} else {
die('Not instanceOf');
}
// Output: Not instanceOf
if ($someClassB instanceof \MyNamespace\A){
die('InstanceOf');
}
// Output: InstanceOf;
// ...
}
Or you can add the use
statement :
namespace MyNamespace\Util;
use MyNamespace\A;
class C {
// ...
}