Get all defined classes of a parent class in php
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to determine, after all files have been included, which classes extend a parent class, so: class foo{ } class boo extends foo{ } class bar extends foo{ } and I'd like to be able to grab an array like: array('boo','bar'); 回答1: If you need that, it really smells like bad code, the base class shouldn't need to know this. However, if you definitions have been included (i.e. you don't need to include new files with classes you possibly have), you could run: $children = array(); foreach(get_declared_classes() as $class){ if($class