Code: Select all
class A
{
}
class B {
public static function testInstanceOf($enforceType)
{
return __CLASS__ instanceof $enforceType;
}
}
var_dump(B::testInstanceOf('A')); // does A exist as a class?Interestingly if I use self instead of __CLASS__ it complains that self is an undefined constant!
I've found that this:
Code: Select all
class A
{
}
class B {
public static function testInstanceOf($enforceType)
{
$a = new $enforceType();
}
}
var_dump(B::testInstanceOf('notaclass'));So is reflection my only option?
Edit:
Code: Select all
$reflection = new ReflectionClass($enforceType);