A topological sort is useful for determining dependency loading.
An OO implementation of a topological sort algorithm in PHP. This code has been included in the MediaWiki project with thanks to Jeroen De Dauw.
A more up-to-date version of this class is maintained at the openSUSE MediaWiki project: https://github.com/openSUSE/wiki/blob/master/extensions/Validator/includes/TopologicalSort.php