PHP 8 compatibility (curly brace string access)
[pharext/pharext] / src / pharext / Cli / Args.php
index c248a74dcc964c81c089d1b2204a8cacfe3dcfb0..ef46e88a4cb286794da15f70a2069ae2d9768300 100644 (file)
@@ -128,14 +128,14 @@ class Args implements \ArrayAccess
                for ($f = false, $p = 0, $i = 0; $i < $argc; ++$i) {
                        $o = $argv[$i];
 
-                       if ($o{0} === "-" && strlen($o) > 2 && $o{1} !== "-") {
+                       if ($o[0] === "-" && strlen($o) > 2 && $o[1] !== "-") {
                                // multiple short opts, e.g. -vps
                                $argc += strlen($o) - 2;
                                array_splice($argv, $i, 1, array_map(function($s) {
                                        return "-$s";
                                }, str_split(substr($o, 1))));
                                $o = $argv[$i];
-                       } elseif ($o{0} === "-" && strlen($o) > 2 && $o{1} === "-" && 0 < ($eq = strpos($o, "="))) {
+                       } elseif ($o[0] === "-" && strlen($o) > 2 && $o[1] === "-" && 0 < ($eq = strpos($o, "="))) {
                                // long opt with argument, e.g. --foo=bar
                                $argc++;
                                array_splice($argv, $i, 1, [
@@ -150,7 +150,7 @@ class Args implements \ArrayAccess
                        }
 
                        if ($f || !isset($this->spec[$o])) {
-                               if ($o{0} !== "-" && isset($this->spec["--$p"])) {
+                               if ($o[0] !== "-" && isset($this->spec["--$p"])) {
                                        $this[$p] = $o;
                                        if (!$this->optIsMulti($p)) {
                                                ++$p;
@@ -207,7 +207,7 @@ class Args implements \ArrayAccess
                $args = [];
                foreach ($this->spec as $spec) {
                        $opt = $this->opt($spec[1]);
-                       $args[$opt] = $this[$opt];
+                       $args[$opt] = is_numeric($spec[0]) ? $this[$spec[0]] : $this[$opt];
                }
                return $args;
        }
@@ -316,7 +316,7 @@ class Args implements \ArrayAccess
                if (is_numeric($o)) {
                        return "--$o";
                }
-               if ($o{0} !== '-') {
+               if ($o[0] !== '-') {
                        if (strlen($o) > 1) {
                                $o = "-$o";
                        }