How to load a file located in core/includes? I'd like to execute PHP code that requires functions available in the includes files of core located in core/includes.

I found ModuleHandler()-&gt;loadInclude() and module_load_include() but I am afraid this 2 options can load files from core/modules directory only, according to the doc, but may be I misinterpreted it:


  Loads a module include file.


For example if I execute:

\Drupal::moduleHandler()-&gt;loadInclude('core', 'inc', 'install');
drupal_rewrite_settings(); // the func that I want located in install.inc


I get:

Call to undefined function drupal_rewrite_settings()


which means install.inc has not been loaded.
You can use a good old fashioned include_once (or require_once):

include_once DRUPAL_ROOT . '/core/includes/install.inc';


Core uses the same method any time it needs to source a file in core/includes. Case in point, ModuleHandler::loadInclude itself does exactly that if the file extension provided is "install":

public function loadInclude($module, $type, $name = NULL) {
  if ($type == 'install') {
    // Make sure the installation API is available
    include_once $this-&gt;root . '/core/includes/install.inc';
  }

  ...