[ACCEPTED]-How to check instanceof parent class?-instanceof

Accepted answer
Score: 17

Following example returns true:

class parentTroll {}
class troll extends parentTroll {}
$troll = new troll();

var_dump($troll instanceof parentTroll);


boolean true

You 1 can also use ReflectionClass:

var_dump((new ReflectionClass($troll))->getParentClass()->getName() == 'parentTroll');
Score: 2

The documentation disagrees

See http://www.php.net/manual/en/language.operators.type.php

And so does 1 my testing of your code.

Score: 0

There is metho is_subclass_of. Just use 1 is_subclass_of($troll, Parent::class)

More Related questions