diff --git a/src/Ulrichsg/Getopt/Getopt.php b/src/Ulrichsg/Getopt/Getopt.php
index bd6b7ad5279efe25a82a8dd1c9bcc03ef8513301..33d399bef5ac8b0e25ac379f9f5b7745fcebeda3 100644
--- a/src/Ulrichsg/Getopt/Getopt.php
+++ b/src/Ulrichsg/Getopt/Getopt.php
@@ -123,7 +123,13 @@ class Getopt implements \Countable, \ArrayAccess, \IteratorAggregate
         if (!isset($arguments)) {
             global $argv;
             $arguments = $argv;
-            $this->scriptName = array_shift($arguments); // $argv[0] is the script's name
+            // $argv can be null, e.g. when running from web server or when
+            // register_argc_argv is disabled
+            if($arguments === null) {
+                $this->scriptName = $_SERVER['PHP_SELF'];
+            } else {
+                $this->scriptName = array_shift($arguments); // $argv[0] is the script's name
+            }
         } elseif (is_string($arguments)) {
             $this->scriptName = $_SERVER['PHP_SELF'];
             $arguments = explode(' ', $arguments);