Say I have this:
class Bird{}
class PrettyBird extends Bird{}
class UglyBird extends Bird{}
class Duckling extends UglyBird{}
and I do this:
$bird = new Duckling();
OR
$bird = new UglyBird();
Suppose in my universe all I am interested in is if class belongs to UglyBird
or PrettyBird
. In case above, I want to test whether $bird
belongs to UglyBird
(super)class in both cases above.
How?
Currently I can do it by
if (get_class($bird) === UglyBird::class
or get_class($bird) === Duckling::class)
print "MATCH!";
but that's impractical. For example, what if I create a new class that extends UglyBird
. I will have to add that class into the if
statement.