Difference between $this->config and \Drupal::config in ConfigFormBase I want to override a custom module configuration in the settings.php file. So the configuration in database can be independent from the environment.

$config['my_module.settings']['prop'] = 'foo';


I my module configuration form, the config result is different given the method I use to get it :

class MyConfigurationForm extends ConfigFormBase {

    public function buildForm( array $form, FormStateInterface $form_state ){
        $config = $this-&gt;config( 'my_module.settings' );
        print_r( $config-&gt;get('prop') ); 
        // prints database value, or nothing if there is no value in database for 'prop'

        $config = \Drupal::config( 'my_module.settings' );
        print_r( $config-&gt;get('prop') ); 
        // prints 'foo'
    }

}


Why is that ? 
What's the difference between these two methods ?
In a configuration form use $this-&gt;config() and not \Drupal::config().

The difference between both is that the configuration form uses immutable configuration. 

When Drupal 8 was in beta, the immutable configuration was introduced to avoid bleeding of overridden values into configuration when saved to the database. See the change record:

Configuration objects by default are immutable

This is the code executed by $this-&gt;config() of a configuration form, in a static version:

\Drupal::configFactory()-&gt;getEditable('system.site')-&gt;set('name', 'My fantastic site')-&gt;save();




For Drupal 8.7 it is discussed to display a warning for overridden values:


  This form contains values that have been overridden. Changes to these
  values can still be saved, but the overridden values will take
  precedence. Overrides are as follows ...


See the issue:

There is no indication on configuration forms if there are overridden values