diff --git a/core/lib/Drupal/Core/Asset/CssOptimizer.php b/core/lib/Drupal/Core/Asset/CssOptimizer.php
--- a/core/lib/Drupal/Core/Asset/CssOptimizer.php
+++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php
@@ -141,7 +141,7 @@ public function loadFile($file, $optimize = NULL, $reset_basepath = TRUE) {
     // Store the parent base path to restore it later.
     $parent_base_path = $basepath;
     // Set the current base path to process possible child imports.
-    $basepath = dirname($file);
+    $basepath = dirname($file ?? '');
 
     // Load the CSS stylesheet. We suppress errors because themes may specify
     // stylesheets in their .info.yml file that don't exist in the theme's path,
@@ -192,7 +192,7 @@ protected function loadNestedFile($matches) {
     $file = $this->loadFile($filename, NULL, FALSE);
 
     // Determine the file's directory.
-    $directory = dirname($filename);
+    $directory = dirname($filename ?? '');
     // If the file is in the current directory, make sure '.' doesn't appear in
     // the url() path.
     $directory = $directory == '.' ? '' : $directory . '/';
diff --git a/core/lib/Drupal/Core/Command/GenerateProxyClassCommand.php b/core/lib/Drupal/Core/Command/GenerateProxyClassCommand.php
--- a/core/lib/Drupal/Core/Command/GenerateProxyClassCommand.php
+++ b/core/lib/Drupal/Core/Command/GenerateProxyClassCommand.php
@@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
 EOF;
       $file_string = str_replace(['{{ proxy_class_name }}', '{{ proxy_class_string }}'], [$proxy_class_name, $proxy_class_string], $file_string);
 
-      mkdir(dirname($proxy_filename), 0775, TRUE);
+      mkdir(dirname($proxy_filename ?? ''), 0775, TRUE);
       file_put_contents($proxy_filename, $file_string);
 
       $output->writeln(sprintf('Proxy of class %s written to %s', $class_name, $proxy_filename));
diff --git a/core/lib/Drupal/Core/Command/GenerateTheme.php b/core/lib/Drupal/Core/Command/GenerateTheme.php
--- a/core/lib/Drupal/Core/Command/GenerateTheme.php
+++ b/core/lib/Drupal/Core/Command/GenerateTheme.php
@@ -32,7 +32,7 @@ class GenerateTheme extends Command {
   public function __construct(string $name = NULL) {
     parent::__construct($name);
 
-    $this->root = dirname(__DIR__, 5);
+    $this->root = dirname(__DIR__ ?? '', 5);
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Command/InstallCommand.php b/core/lib/Drupal/Core/Command/InstallCommand.php
--- a/core/lib/Drupal/Core/Command/InstallCommand.php
+++ b/core/lib/Drupal/Core/Command/InstallCommand.php
@@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
     }
 
     // Change the directory to the Drupal root.
-    chdir(dirname(__DIR__, 5));
+    chdir(dirname(__DIR__ ?? '', 5));
 
     // Check whether there is already an installation.
     if ($this->isDrupalInstalled()) {
diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
--- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
+++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
@@ -421,7 +421,7 @@ public function databaseType() {
    */
   public function createDatabase($database) {
     // Verify the database is writable.
-    $db_directory = new \SplFileInfo(dirname($database));
+    $db_directory = new \SplFileInfo(dirname($database ?? ''));
     if (!$db_directory->isDir() && !\Drupal::service('file_system')->mkdir($db_directory->getPathName(), 0755, TRUE)) {
       throw new DatabaseNotFoundException('Unable to create database directory ' . $db_directory->getPathName());
     }
diff --git a/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php
--- a/core/lib/Drupal/Core/Database/Install/Tasks.php
+++ b/core/lib/Drupal/Core/Database/Install/Tasks.php
@@ -247,7 +247,7 @@ public function getFormOptions(array $database) {
     // @todo https:///www.drupal.org/node/3123240 Provide a better way to get
     //   the driver name.
     $reflection = new \ReflectionClass($this);
-    $dir_parts = explode(DIRECTORY_SEPARATOR, dirname($reflection->getFileName(), 2));
+    $dir_parts = explode(DIRECTORY_SEPARATOR, dirname($reflection->getFileName() ?? '', 2));
     $driver = array_pop($dir_parts);
 
     $form['database'] = [
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -308,7 +308,7 @@ protected static function guessApplicationRoot() {
     // - Removing the namespace directories from the path.
     // - Getting the path to the directory two levels up from the path
     //   determined in the previous step.
-    return dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
+    return dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)) ?? '', 2);
   }
 
   /**
@@ -648,7 +648,7 @@ public function discoverServiceProviders() {
       if (class_exists($class)) {
         $this->serviceProviderClasses['app'][$module] = $class;
       }
-      $filename = dirname($filename) . "/$module.services.yml";
+      $filename = dirname($filename ?? '') . "/$module.services.yml";
       if (file_exists($filename)) {
         $this->serviceYamls['app'][$module] = $filename;
       }
@@ -1093,7 +1093,7 @@ protected function initializeRequestGlobals(Request $request) {
 
     // For a request URI of '/index.php/foo', $_SERVER['SCRIPT_NAME'] is
     // '/index.php', whereas $_SERVER['PHP_SELF'] is '/index.php/foo'.
-    if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME')), '\/')) {
+    if ($dir = rtrim(dirname($request->server->get('SCRIPT_NAME') ?? ''), '\/')) {
       // Remove "core" directory if present, allowing install.php,
       // authorize.php, and others to auto-detect a base path.
       $core_position = strrpos($dir, '/core');
@@ -1430,7 +1430,7 @@ protected function getModuleFileNames() {
   protected function getModuleNamespacesPsr4($module_file_names) {
     $namespaces = [];
     foreach ($module_file_names as $module => $filename) {
-      $namespaces["Drupal\\$module"] = dirname($filename) . '/src';
+      $namespaces["Drupal\\$module"] = dirname($filename ?? '') . '/src';
     }
     return $namespaces;
   }
diff --git a/core/lib/Drupal/Core/Extension/Extension.php b/core/lib/Drupal/Core/Extension/Extension.php
--- a/core/lib/Drupal/Core/Extension/Extension.php
+++ b/core/lib/Drupal/Core/Extension/Extension.php
@@ -95,7 +95,7 @@ public function getName() {
    * @return string
    */
   public function getPath() {
-    return dirname($this->pathname);
+    return dirname($this->pathname ?? '');
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
--- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
@@ -464,7 +464,7 @@ protected function scanDirectory($dir, $include_tests) {
         else {
           $filename = $name . '.' . $type;
         }
-        if (!file_exists($this->root . '/' . dirname($pathname) . '/' . $filename)) {
+        if (!file_exists($this->root . '/' . dirname($pathname ?? '') . '/' . $filename)) {
           $filename = NULL;
         }
         $extension_arguments = [
diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php
--- a/core/lib/Drupal/Core/Extension/ExtensionList.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionList.php
@@ -538,7 +538,7 @@ public function getPathname($extension_name) {
    *   If there is no extension with the supplied name.
    */
   public function getPath($extension_name) {
-    return dirname($this->getPathname($extension_name));
+    return dirname($this->getPathname($extension_name) ?? '');
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php b/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php
--- a/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php
+++ b/core/lib/Drupal/Core/Extension/ExtensionPathResolver.php
@@ -82,7 +82,7 @@ public function getPathname(string $type, string $name): ?string {
    *   If the extension is unknown.
    */
   public function getPath(string $type, string $name): string {
-    return dirname($this->getPathname($type, $name));
+    return dirname($this->getPathname($type, $name) ?? '');
   }
 
 }
diff --git a/core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php b/core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php
--- a/core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php
+++ b/core/lib/Drupal/Core/File/Event/FileUploadSanitizeNameEvent.php
@@ -71,7 +71,7 @@ public function getFilename(): string {
    *   Thrown when $filename contains path information.
    */
   public function setFilename(string $filename): self {
-    if (dirname($filename) !== '.') {
+    if (dirname($filename ?? '') !== '.') {
       throw new \InvalidArgumentException(sprintf('$filename must be a filename with no path information, "%s" provided', $filename));
     }
     $this->filename = $filename;
diff --git a/core/lib/Drupal/Core/File/FileSystem.php b/core/lib/Drupal/Core/File/FileSystem.php

--- a/core/lib/Drupal/Core/File/FileSystem.php
+++ b/core/lib/Drupal/Core/File/FileSystem.php
@@ -146,10 +146,10 @@ public function dirname($uri) {
     $scheme = StreamWrapperManager::getScheme($uri);
 
     if ($this->streamWrapperManager->isValidScheme($scheme)) {
-      return $this->streamWrapperManager->getViaScheme($scheme)->dirname($uri);
+      return $this->streamWrapperManager->getViaScheme($scheme)->dirname($uri ?? '');
     }
     else {
-      return dirname($uri);
+      return dirname($uri ?? '');
     }
   }
 
@@ -467,7 +467,7 @@ protected function prepareDestination($source, &$destination, $replace) {
     }
     else {
       // Perhaps $destination is a dir/file?
-      $dirname = $this->dirname($destination);
+      $dirname = $this->dirname($destination ?? '');
       if (!$this->prepareDirectory($dirname)) {
         $this->logger->error("The specified file '%original_source' could not be copied because the destination directory '%destination_directory' is not properly configured. This may be caused by a problem with file or directory permissions.", [
           '%original_source' => $original_source,
@@ -564,7 +564,7 @@ public function getDestinationFilename($destination, $replace) {
           break;
 
         case FileSystemInterface::EXISTS_RENAME:
-          $directory = $this->dirname($destination);
+          $directory = $this->dirname($destination ?? '');
           $destination = $this->createFilename($basename, $directory);
           break;
 
diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php

--- a/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
+++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
@@ -132,7 +132,7 @@ protected function getLocalPath($uri = NULL) {
     $realpath = realpath($path);
     if (!$realpath) {
       // This file does not yet exist.
-      $realpath = realpath(dirname($path)) . '/' . \Drupal::service('file_system')->basename($path);
+      $realpath = realpath(dirname($path ?? '')) . '/' . \Drupal::service('file_system')->basename($path);
     }
     $directory = realpath($this->getDirectoryPath());
     if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) {
@@ -317,7 +317,7 @@ public function rename($from_uri, $to_uri) {
   public function dirname($uri = NULL) {
     [$scheme] = explode('://', $uri, 2);
     $target = $this->getTarget($uri);
-    $dirname = dirname($target);
+    $dirname = dirname($target ?? '');
 
     if ($dirname == '.') {
       $dirname = '';
diff --git a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php

--- a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
+++ b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php
@@ -91,7 +91,7 @@ public function phpUnitCommand() {
     // reflection. We can determine the vendor directory based on that filename.
     $autoloader = require $this->appRoot . '/autoload.php';
     $reflector = new \ReflectionClass($autoloader);
-    $vendor_dir = dirname($reflector->getFileName(), 2);
+    $vendor_dir = dirname($reflector->getFileName() ?? '', 2);
 
     // The file in Composer's bin dir is a *nix link, which does not work when
     // extracted from a tarball and generally not on Windows.
diff --git a/core/lib/Drupal/Core/Updater/Module.php b/core/lib/Drupal/Core/Updater/Module.php

--- a/core/lib/Drupal/Core/Updater/Module.php
+++ b/core/lib/Drupal/Core/Updater/Module.php
@@ -28,7 +28,7 @@ public function getInstallDirectory() {
     if ($this->isInstalled() && ($relative_path = \Drupal::service('extension.list.module')->getPath($this->name))) {
       // The return value of ExtensionList::getPath() is always relative to the
       // site, so prepend DRUPAL_ROOT.
-      return DRUPAL_ROOT . '/' . dirname($relative_path);
+      return DRUPAL_ROOT . '/' . dirname($relative_path ?? '');
     }
     else {
       // When installing a new module, prepend the requested root directory.
diff --git a/core/lib/Drupal/Core/Updater/Theme.php b/core/lib/Drupal/Core/Updater/Theme.php

--- a/core/lib/Drupal/Core/Updater/Theme.php
+++ b/core/lib/Drupal/Core/Updater/Theme.php
@@ -30,7 +30,7 @@ public function getInstallDirectory() {
       // The return value of
       // \Drupal::service('extension.list.theme')->getPath() is always relative
       // to the site, so prepend DRUPAL_ROOT.
-      return DRUPAL_ROOT . '/' . dirname($relative_path);
+      return DRUPAL_ROOT . '/' . dirname($relative_path ?? '');
     }
     else {
       // When installing a new theme, prepend the requested root directory.
diff --git a/core/lib/Drupal/Core/Updater/Updater.php b/core/lib/Drupal/Core/Updater/Updater.php

--- a/core/lib/Drupal/Core/Updater/Updater.php
+++ b/core/lib/Drupal/Core/Updater/Updater.php
@@ -309,7 +309,7 @@ public function install(&$filetransfer, $overrides = []) {
   public function prepareInstallDirectory(&$filetransfer, $directory) {
     // Make the parent dir writable if need be and create the dir.
     if (!is_dir($directory)) {
-      $parent_dir = dirname($directory);
+      $parent_dir = dirname($directory ?? '');
       if (!is_writable($parent_dir)) {
         @chmod($parent_dir, 0755);
         // It is expected that this will fail if the directory is owned by the
