If the code has access to the file that holds the sensitive information then surely the developer has access to the contents of that file either directly or through their code.
The developer is not developing on the production system* and therefore does not have access to either the production DB credentials or indeed the production DB itself. Putting this in a config file which is just data and not something to be executed allows the developer to test on the dev system with the dev DB credentials and the dev DB without any leak of sensitive information. All the code may be shared between development and production quite safely and only the config files (which are now not code) are kept separately.
* If that isn't the case then stop whatever it is you are doing and set up a separate system just for development. Never develop on production.