[ACCEPTED]-How to check instanceof parent class?-instanceof
Accepted answer
Following example returns true:
class parentTroll {}
class troll extends parentTroll {}
$troll = new troll();
var_dump($troll instanceof parentTroll);
Output:
boolean true
You 1 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 1 my testing of your code.
There is metho is_subclass_of. Just use 1 is_subclass_of($troll, Parent::class)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.