3v4l.org

run code in 300+ PHP versions simultaneously
<?php class father {} class child1 extends father {} class child2 extends father {} class child3 extends father {} class notMe {} function getChildrenOf(string $parentClass): array { if (!class_exists($parentClass)) { return []; } $classes = []; $classes = array_filter(get_declared_classes(), function($class) use($parentClass) { return is_a($class, $parentClass, true); }); return $classes; } $childrenClasses = getChildrenOf(father::class); var_dump($childrenClasses);
Output for 8.3.0 - 8.3.7
array(4) { [194]=> string(6) "father" [195]=> string(6) "child1" [196]=> string(6) "child2" [197]=> string(6) "child3" }
Output for 8.2.0 - 8.2.19
array(4) { [182]=> string(6) "father" [183]=> string(6) "child1" [184]=> string(6) "child2" [185]=> string(6) "child3" }
Output for 8.1.0 - 8.1.28
array(4) { [171]=> string(6) "father" [172]=> string(6) "child1" [173]=> string(6) "child2" [174]=> string(6) "child3" }
Output for 7.4.0 - 7.4.32, 8.0.1 - 8.0.12, 8.0.14 - 8.0.30
array(4) { [162]=> string(6) "father" [163]=> string(6) "child1" [164]=> string(6) "child2" [165]=> string(6) "child3" }
Output for 8.0.13
array(4) { [141]=> string(6) "father" [142]=> string(6) "child1" [143]=> string(6) "child2" [144]=> string(6) "child3" }
Output for 8.0.0
array(4) { [161]=> string(6) "father" [162]=> string(6) "child1" [163]=> string(6) "child2" [164]=> string(6) "child3" }
Output for 7.4.33
array(4) { [140]=> string(6) "father" [141]=> string(6) "child1" [142]=> string(6) "child2" [143]=> string(6) "child3" }
Output for 7.3.32 - 7.3.33
array(4) { [139]=> string(6) "father" [140]=> string(6) "child1" [141]=> string(6) "child2" [142]=> string(6) "child3" }
Output for 7.3.0 - 7.3.31
array(4) { [160]=> string(6) "father" [161]=> string(6) "child1" [162]=> string(6) "child2" [163]=> string(6) "child3" }
Output for 7.2.0 - 7.2.33
array(4) { [158]=> string(6) "father" [159]=> string(6) "child1" [160]=> string(6) "child2" [161]=> string(6) "child3" }
Output for 7.1.25 - 7.1.30
array(4) { [156]=> string(6) "father" [157]=> string(6) "child1" [158]=> string(6) "child2" [159]=> string(6) "child3" }

preferences:
120.35 ms | 402 KiB | 171 Q