src/PEAR/Installer.php
function sortPackagesForUninstall(&$packages)
    {
        $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->config);
        if (PEAR::isError($this->_dependencyDB)) {
            return $this->_dependencyDB;
        }
        usort($packages, array(&$this, '_sortUninstall'));
    }
function sortPackagesForUninstall(&$packages)
    {
        $this->_dependencyDB = &PEAR_DependencyDB::singleton($this->config);
        if (PEAR::isError($this->_dependencyDB)) {
            return $this->_dependencyDB;
        }
        usort($packages, array(&$this, '_sortUninstall'));
    }
Sort a list of arrays of array(downloaded packagefilename) by dependency.

It also removes duplicate dependencies
@param array an array of PEAR_PackageFile_v[1/2] objects
@return array|PEAR_Error array of array(packagefilename, package.xml contents)