settings.php files are include()ed twice on some pages, so if you try to define a function of class there, it breaks, as you found.
The solution is to define these things in a separate file (typically called settingslib.php) and then require_once() settingslib.php from settings.php.