In PHP there is two classes:
class parentTroll {...}
and class troll extends parentTroll {...}
And then there is an object $troll = new troll();
How to check $troll instanceof parentTroll
? This line returns false now.
In PHP there is two classes:
class parentTroll {...}
and class troll extends parentTroll {...}
And then there is an object $troll = new troll();
How to check $troll instanceof parentTroll
? This line returns false now.
Following example returns true:
class parentTroll {}
class troll extends parentTroll {}
$troll = new troll();
var_dump($troll instanceof parentTroll);
Output:
boolean true
You can also use ReflectionClass
:
var_dump((new ReflectionClass($troll))->getParentClass()->getName() == 'parentTroll');
The documentation disagrees
See http://www.php.net/manual/en/language.operators.type.php
And so does my testing of your code.
There is metho is_subclass_of. Just use is_subclass_of($troll, Parent::class)
© 2022 - 2024 — McMap. All rights reserved.