public function dumpChanges($header = '')
    {
        $userSettingsFile = $this->getUserSettingsFile();

        $defaultSettings = $this->getMergedDefaultSettings();
        $existingMutableSettings = $this->settingsChain[$userSettingsFile];

        $dirty = false;

        $configToWrite = array();
        foreach ($this->mergedSettings as $sectionName => $changedSection) {
            if(isset($existingMutableSettings[$sectionName])){
                $existingMutableSection = $existingMutableSettings[$sectionName];
            } else{
                $existingMutableSection = array();
            }

            // remove default values from both (they should not get written to local)
            if (isset($defaultSettings[$sectionName])) {
                $changedSection = $this->arrayUnmerge($defaultSettings[$sectionName], $changedSection);
                $existingMutableSection = $this->arrayUnmerge($defaultSettings[$sectionName], $existingMutableSection);
            }

            // if either local/config have non-default values and the other doesn't,
            // OR both have values, but different values, we must write to config.ini.php
            if (empty($changedSection) xor empty($existingMutableSection)
                || (!empty($changedSection)
                    && !empty($existingMutableSection)
                    && self::compareElements($changedSection, $existingMutableSection))
            ) {
                $dirty = true;
            }

            $configToWrite[$sectionName] = $changedSection;
        }

        if ($dirty) {
            // sort config sections by how early they appear in the file chain
            $self = $this;
            uksort($configToWrite, function ($sectionNameLhs, $sectionNameRhs) use ($self) {
                $lhsIndex = $self->findIndexOfFirstFileWithSection($sectionNameLhs);
                $rhsIndex = $self->findIndexOfFirstFileWithSection($sectionNameRhs);

                if ($lhsIndex == $rhsIndex) {
                    $lhsIndexInFile = $self->getIndexOfSectionInFile($lhsIndex, $sectionNameLhs);
                    $rhsIndexInFile = $self->getIndexOfSectionInFile($rhsIndex, $sectionNameRhs);

                    if ($lhsIndexInFile == $rhsIndexInFile) {
                        return 0;
                    } elseif ($lhsIndexInFile < $rhsIndexInFile) {
                        return -1;
                    } else {
                        return 1;
                    }
                } elseif ($lhsIndex < $rhsIndex) {
                    return -1;
                } else {
                    return 1;
                }
            });

            return $this->dumpSettings($configToWrite, $header);
        } else {
            return null;
        }
    }