From d87bedbb147d726689a6b83c31648c08af35b3be Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Wed, 7 Aug 2019 07:51:33 +0800 Subject: [PATCH 1/2] Fix PHP 7.4 deprecation: array/string curly braces access Signed-off-by: Jack Cherng --- OS/Guess.php | 2 +- PEAR/Builder.php | 2 +- PEAR/Command.php | 2 +- PEAR/Command/Config.php | 4 ++-- PEAR/Common.php | 4 ++-- PEAR/Config.php | 2 +- PEAR/DependencyDB.php | 2 +- PEAR/Downloader.php | 2 +- PEAR/Installer/Role.php | 2 +- PEAR/PackageFile.php | 12 ++++++------ PEAR/PackageFile/Generator/v1.php | 6 +++--- PEAR/PackageFile/Generator/v2.php | 2 +- PEAR/PackageFile/v1.php | 4 ++-- PEAR/PackageFile/v2/Validator.php | 12 ++++++------ PEAR/Registry.php | 6 +++--- PEAR/Start.php | 2 +- PEAR/Start/CLI.php | 2 +- PEAR/Validate.php | 6 +++--- System.php | 2 +- 19 files changed, 38 insertions(+), 38 deletions(-) diff --git a/OS/Guess.php b/OS/Guess.php index 79d5cfe36..d5aa295c3 100644 --- a/OS/Guess.php +++ b/OS/Guess.php @@ -253,7 +253,7 @@ function _detectGlibcVersion() fclose($fp); $cpp = popen("/usr/bin/cpp $tmpfile", "r"); while ($line = fgets($cpp, 1024)) { - if ($line{0} == '#' || trim($line) == '') { + if ($line[0] == '#' || trim($line) == '') { continue; } diff --git a/PEAR/Builder.php b/PEAR/Builder.php index 807a8520b..2c51a8e4f 100644 --- a/PEAR/Builder.php +++ b/PEAR/Builder.php @@ -191,7 +191,7 @@ function _harvestInstDir($dest_prefix, $dirname, &$built_files) $ret = true; while (($ent = readdir($d)) !== false) { - if ($ent{0} == '.') + if ($ent[0] == '.') continue; $full = $dirname . DIRECTORY_SEPARATOR . $ent; diff --git a/PEAR/Command.php b/PEAR/Command.php index eb9543906..77d722bf7 100644 --- a/PEAR/Command.php +++ b/PEAR/Command.php @@ -233,7 +233,7 @@ public static function registerCommands($merge = false, $dir = null) } while ($file = readdir($dp)) { - if ($file{0} == '.' || substr($file, -4) != '.xml') { + if ($file[0] == '.' || substr($file, -4) != '.xml') { continue; } diff --git a/PEAR/Command/Config.php b/PEAR/Command/Config.php index f3174aef3..01d12eed0 100644 --- a/PEAR/Command/Config.php +++ b/PEAR/Command/Config.php @@ -315,7 +315,7 @@ function doConfigCreate($command, $options, $params) $root = preg_replace(array('!\\\\+!', '!/+!', "!$ds2+!"), array('/', '/', '/'), $root); - if ($root{0} != '/') { + if ($root[0] != '/') { if (!isset($options['windows'])) { return PEAR::raiseError('Root directory must be an absolute path beginning ' . 'with "/", was: "' . $root . '"'); @@ -338,7 +338,7 @@ function doConfigCreate($command, $options, $params) $params[1] = realpath($params[1]); $config = new PEAR_Config($params[1], '#no#system#config#', false, false); - if ($root{strlen($root) - 1} == '/') { + if ($root[strlen($root) - 1] == '/') { $root = substr($root, 0, strlen($root) - 1); } diff --git a/PEAR/Common.php b/PEAR/Common.php index c15591a98..11a325d98 100644 --- a/PEAR/Common.php +++ b/PEAR/Common.php @@ -686,7 +686,7 @@ function buildProvidesArray($srcinfo) foreach ($methods as $method) { $function = "$class::$method"; $key = "function;$function"; - if ($method{0} == '_' || !strcasecmp($method, $class) || + if ($method[0] == '_' || !strcasecmp($method, $class) || isset($this->pkginfo['provides'][$key])) { continue; } @@ -698,7 +698,7 @@ function buildProvidesArray($srcinfo) foreach ($srcinfo['declared_functions'] as $function) { $key = "function;$function"; - if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) { + if ($function[0] == '_' || isset($this->pkginfo['provides'][$key])) { continue; } diff --git a/PEAR/Config.php b/PEAR/Config.php index 0d02c4ce4..ea4c320eb 100644 --- a/PEAR/Config.php +++ b/PEAR/Config.php @@ -2092,7 +2092,7 @@ static function _prependPath($path, $prepend) if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) { if (preg_match('/^[a-z]:/i', $prepend)) { $prepend = substr($prepend, 2); - } elseif ($prepend{0} != '\\') { + } elseif ($prepend[0] != '\\') { $prepend = "\\$prepend"; } $path = substr($path, 0, 2) . $prepend . substr($path, 2); diff --git a/PEAR/DependencyDB.php b/PEAR/DependencyDB.php index 4f633ff1f..319074b05 100644 --- a/PEAR/DependencyDB.php +++ b/PEAR/DependencyDB.php @@ -174,7 +174,7 @@ function assertDepsDB() $this->rebuildDB(); } - if ($depdb['_version']{0} > $this->_version{0}) { + if ($depdb['_version']{0} > $this->_version[0]) { return PEAR::raiseError('Dependency database is version ' . $depdb['_version'] . ', and we are version ' . $this->_version . ', cannot continue'); diff --git a/PEAR/Downloader.php b/PEAR/Downloader.php index b1427c430..6996d3d9a 100644 --- a/PEAR/Downloader.php +++ b/PEAR/Downloader.php @@ -1156,7 +1156,7 @@ function _prependPath($path, $prepend) if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) { if (preg_match('/^[a-z]:/i', $prepend)) { $prepend = substr($prepend, 2); - } elseif ($prepend{0} != '\\') { + } elseif ($prepend[0] != '\\') { $prepend = "\\$prepend"; } $path = substr($path, 0, 2) . $prepend . substr($path, 2); diff --git a/PEAR/Installer/Role.php b/PEAR/Installer/Role.php index 7bed4eaea..ce30d8f79 100644 --- a/PEAR/Installer/Role.php +++ b/PEAR/Installer/Role.php @@ -237,7 +237,7 @@ public static function registerRoles($dir = null) } while ($entry = readdir($dp)) { - if ($entry{0} == '.' || substr($entry, -4) != '.xml') { + if ($entry[0] == '.' || substr($entry, -4) != '.xml') { continue; } diff --git a/PEAR/PackageFile.php b/PEAR/PackageFile.php index b1252ae0b..e483337c5 100644 --- a/PEAR/PackageFile.php +++ b/PEAR/PackageFile.php @@ -94,13 +94,13 @@ function setLogger(&$l) */ function &parserFactory($version) { - if (!in_array($version{0}, array('1', '2'))) { + if (!in_array($version[0], array('1', '2'))) { $a = false; return $a; } - include_once 'PEAR/PackageFile/Parser/v' . $version{0} . '.php'; - $version = $version{0}; + include_once 'PEAR/PackageFile/Parser/v' . $version[0] . '.php'; + $version = $version[0]; $class = "PEAR_PackageFile_Parser_v$version"; $a = new $class; return $a; @@ -122,13 +122,13 @@ function getClassPrefix() */ function &factory($version) { - if (!in_array($version{0}, array('1', '2'))) { + if (!in_array($version[0], array('1', '2'))) { $a = false; return $a; } - include_once 'PEAR/PackageFile/v' . $version{0} . '.php'; - $version = $version{0}; + include_once 'PEAR/PackageFile/v' . $version[0] . '.php'; + $version = $version[0]; $class = $this->getClassPrefix() . $version; $a = new $class; return $a; diff --git a/PEAR/PackageFile/Generator/v1.php b/PEAR/PackageFile/Generator/v1.php index 739a83470..db882cf40 100644 --- a/PEAR/PackageFile/Generator/v1.php +++ b/PEAR/PackageFile/Generator/v1.php @@ -904,7 +904,7 @@ function _convertRelease2_0(&$release, $package) if (isset($package['install-as'][$file])) { continue; } - if ($platform{0} != '!') { + if ($platform[0] != '!') { //o tags for $genericIgnore[] = $file; } @@ -913,7 +913,7 @@ function _convertRelease2_0(&$release, $package) $oses = $notplatform = $platform = array(); foreach ($package['platform'] as $file => $os) { // get a list of oses - if ($os{0} == '!') { + if ($os[0] == '!') { if (isset($oses[substr($os, 1)])) { continue; } @@ -1010,7 +1010,7 @@ function _convertRelease2_0(&$release, $package) continue; } //o tags for - if ($platform{0} != '!' && $platform != $os) { + if ($platform[0] != '!' && $platform != $os) { $release[$releaseNum]['filelist']['ignore'][] = array( 'attribs' => array( diff --git a/PEAR/PackageFile/Generator/v2.php b/PEAR/PackageFile/Generator/v2.php index 53555010e..9e535792a 100644 --- a/PEAR/PackageFile/Generator/v2.php +++ b/PEAR/PackageFile/Generator/v2.php @@ -781,7 +781,7 @@ function _serializeArray(&$array, $tagName = null, $attributes = array()) } } - if (is_string($value) && $value && ($value{strlen($value) - 1} == "\n")) { + if (is_string($value) && $value && ($value[strlen($value) - 1] == "\n")) { $value .= str_repeat($this->options['indent'], $this->_tagDepth); } $tmp .= $this->_createXMLTag(array( diff --git a/PEAR/PackageFile/v1.php b/PEAR/PackageFile/v1.php index 711f43b1b..69cb3a6c6 100644 --- a/PEAR/PackageFile/v1.php +++ b/PEAR/PackageFile/v1.php @@ -1575,7 +1575,7 @@ function _buildProvidesArray($srcinfo) foreach ($methods as $method) { $function = "$class::$method"; $key = "function;$function"; - if ($method{0} == '_' || !strcasecmp($method, $class) || + if ($method[0] == '_' || !strcasecmp($method, $class) || isset($this->_packageInfo['provides'][$key])) { continue; } @@ -1586,7 +1586,7 @@ function _buildProvidesArray($srcinfo) foreach ($srcinfo['declared_functions'] as $function) { $key = "function;$function"; - if ($function{0} == '_' || isset($this->_packageInfo['provides'][$key])) { + if ($function[0] == '_' || isset($this->_packageInfo['provides'][$key])) { continue; } if (!strstr($function, '::') && strncasecmp($function, $pn, $pnl)) { diff --git a/PEAR/PackageFile/v2/Validator.php b/PEAR/PackageFile/v2/Validator.php index e26dab368..06109b641 100644 --- a/PEAR/PackageFile/v2/Validator.php +++ b/PEAR/PackageFile/v2/Validator.php @@ -419,7 +419,7 @@ function _processAttribs($choice, $tag, $context) foreach ($tags as $i => $tag) { if (!is_array($tag) || !isset($tag['attribs'])) { foreach ($choice['attribs'] as $attrib) { - if ($attrib{0} != '?') { + if ($attrib[0] != '?') { $ret &= $this->_tagHasNoAttribs($choice['tag'], $context); continue 2; @@ -427,7 +427,7 @@ function _processAttribs($choice, $tag, $context) } } foreach ($choice['attribs'] as $attrib) { - if ($attrib{0} != '?') { + if ($attrib[0] != '?') { if (!isset($tag['attribs'][$attrib])) { $ret &= $this->_tagMissingAttribute($choice['tag'], $attrib, $context); @@ -450,9 +450,9 @@ function _processStructure($key) } return $ret; } - $multi = $key{0}; + $multi = $key[0]; if ($multi == '+' || $multi == '*') { - $ret['multiple'] = $key{0}; + $ret['multiple'] = $key[0]; $key = substr($key, 1); } if (count($attrs = explode('->', $key)) > 1) { @@ -2106,7 +2106,7 @@ function _buildProvidesArray($srcinfo) foreach ($methods as $method) { $function = "$class::$method"; $key = "function;$function"; - if ($method{0} == '_' || !strcasecmp($method, $class) || + if ($method[0] == '_' || !strcasecmp($method, $class) || isset($providesret[$key])) { continue; } @@ -2118,7 +2118,7 @@ function _buildProvidesArray($srcinfo) foreach ($srcinfo['declared_functions'] as $function) { $key = "function;$function"; - if ($function{0} == '_' || isset($providesret[$key])) { + if ($function[0] == '_' || isset($providesret[$key])) { continue; } diff --git a/PEAR/Registry.php b/PEAR/Registry.php index 08987c615..61b756eb8 100644 --- a/PEAR/Registry.php +++ b/PEAR/Registry.php @@ -1187,7 +1187,7 @@ function _listChannels() $dp = opendir($this->channelsdir); while ($ent = readdir($dp)) { - if ($ent{0} == '.' || substr($ent, -4) != '.reg') { + if ($ent[0] == '.' || substr($ent, -4) != '.reg') { continue; } @@ -1238,7 +1238,7 @@ function _listPackages($channel = false) } while ($ent = readdir($dp)) { - if ($ent{0} == '.' || substr($ent, -4) != '.reg') { + if ($ent[0] == '.' || substr($ent, -4) != '.reg') { continue; } @@ -1262,7 +1262,7 @@ function _listChannelPackages($channel) } while ($ent = readdir($dp)) { - if ($ent{0} == '.' || substr($ent, -4) != '.reg') { + if ($ent[0] == '.' || substr($ent, -4) != '.reg') { continue; } $pkglist[] = substr($ent, 0, -4); diff --git a/PEAR/Validate.php b/PEAR/Validate.php index 9aa89a2ca..134fe17a3 100644 --- a/PEAR/Validate.php +++ b/PEAR/Validate.php @@ -209,7 +209,7 @@ function validatePackageName() } $vlen = strlen($test); $majver = substr($name, strlen($name) - $vlen); - while ($majver && !is_numeric($majver{0})) { + while ($majver && !is_numeric($majver[0])) { $majver = substr($majver, 1); } if ($majver != $test) { @@ -328,7 +328,7 @@ function validateVersion() } else { $vlen = strlen($versioncomponents[0] . ''); $majver = substr($name, strlen($name) - $vlen); - while ($majver && !is_numeric($majver{0})) { + while ($majver && !is_numeric($majver[0])) { $majver = substr($majver, 1); } if (($versioncomponents[0] != 0) && $majver != $versioncomponents[0]) { @@ -398,7 +398,7 @@ function validateVersion() if ($this->_packagexml->getExtends()) { $vlen = strlen($versioncomponents[0] . ''); $majver = substr($name, strlen($name) - $vlen); - while ($majver && !is_numeric($majver{0})) { + while ($majver && !is_numeric($majver[0])) { $majver = substr($majver, 1); } if (($versioncomponents[0] != 0) && $majver != $versioncomponents[0]) { diff --git a/System.php b/System.php index aefc85b3f..d5b6a147d 100644 --- a/System.php +++ b/System.php @@ -74,7 +74,7 @@ public static function _parseArgs($argv, $short_options, $long_options = null) $offset = 0; foreach ($av as $a) { $b = trim($a[0]); - if ($b{0} == '"' || $b{0} == "'") { + if ($b[0] == '"' || $b[0] == "'") { continue; } From 49af2f4cae6f2910fbca31febea12c7617fa7377 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Wed, 4 Sep 2019 17:41:04 +0800 Subject: [PATCH 2/2] Fix PHP 7.4 deprecation: array/string curly braces access Signed-off-by: Jack Cherng --- PEAR/Command/Channels.php | 2 +- PEAR/Command/Common.php | 2 +- PEAR/DependencyDB.php | 2 +- PEAR/Installer.php | 2 +- PEAR/PackageFile/Generator/v1.php | 8 ++++---- PEAR/PackageFile/v2/Validator.php | 4 ++-- PEAR/Registry.php | 2 +- PEAR/Validate.php | 4 ++-- System.php | 2 +- make-gopear-phar.php | 2 +- make-installpear-nozlib-phar.php | 2 +- make-pear-bundle.php | 4 ++-- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/PEAR/Command/Channels.php b/PEAR/Command/Channels.php index 0319593dd..1253eab5d 100644 --- a/PEAR/Command/Channels.php +++ b/PEAR/Command/Channels.php @@ -673,7 +673,7 @@ function doAlias($command, $options, $params) return $this->raiseError('No channel alias specified'); } - if (count($params) !== 2 || (!empty($params[1]) && $params[1]{0} == '-')) { + if (count($params) !== 2 || (!empty($params[1]) && $params[1][0] == '-')) { return $this->raiseError( 'Invalid format, correct is: channel-alias channel alias'); } diff --git a/PEAR/Command/Common.php b/PEAR/Command/Common.php index a9bc80ff2..365c64eb2 100644 --- a/PEAR/Command/Common.php +++ b/PEAR/Command/Common.php @@ -146,7 +146,7 @@ function getGetoptArgs($command, &$short_args, &$long_args) foreach ($this->commands[$command]['options'] as $option => $info) { $larg = $sarg = ''; if (isset($info['arg'])) { - if ($info['arg']{0} == '(') { + if ($info['arg'][0] == '(') { $larg = '=='; $sarg = '::'; $arg = substr($info['arg'], 1, -1); diff --git a/PEAR/DependencyDB.php b/PEAR/DependencyDB.php index 319074b05..5ad831667 100644 --- a/PEAR/DependencyDB.php +++ b/PEAR/DependencyDB.php @@ -174,7 +174,7 @@ function assertDepsDB() $this->rebuildDB(); } - if ($depdb['_version']{0} > $this->_version[0]) { + if ($depdb['_version'][0] > $this->_version[0]) { return PEAR::raiseError('Dependency database is version ' . $depdb['_version'] . ', and we are version ' . $this->_version . ', cannot continue'); diff --git a/PEAR/Installer.php b/PEAR/Installer.php index 5c503852e..ed3c6ea46 100644 --- a/PEAR/Installer.php +++ b/PEAR/Installer.php @@ -225,7 +225,7 @@ function _installFile($file, $atts, $tmp_path, $options) $os = new OS_Guess(); } - if (strlen($atts['platform']) && $atts['platform']{0} == '!') { + if (strlen($atts['platform']) && $atts['platform'][0] == '!') { $negate = true; $platform = substr($atts['platform'], 1); } else { diff --git a/PEAR/PackageFile/Generator/v1.php b/PEAR/PackageFile/Generator/v1.php index db882cf40..8c0fa452b 100644 --- a/PEAR/PackageFile/Generator/v1.php +++ b/PEAR/PackageFile/Generator/v1.php @@ -889,13 +889,13 @@ function _convertRelease2_0(&$release, $package) } //o tags for if (isset($package['platform'][$file]) && - $package['platform'][$file]{0} == '!') { + $package['platform'][$file][0] == '!') { $generic[] = $file; continue; } //o tags for if (isset($package['platform'][$file]) && - $package['platform'][$file]{0} != '!') { + $package['platform'][$file][0] != '!') { $genericIgnore[] = $file; continue; } @@ -959,7 +959,7 @@ function _convertRelease2_0(&$release, $package) // if (isset($package['platform'][$file]) && $package['platform'][$file] != "!$os" && - $package['platform'][$file]{0} == '!') { + $package['platform'][$file][0] == '!') { $release[$releaseNum]['filelist']['install'][] = array( 'attribs' => array( @@ -984,7 +984,7 @@ function _convertRelease2_0(&$release, $package) //o tags for // if (isset($package['platform'][$file]) && - $package['platform'][$file]{0} != '!' && + $package['platform'][$file][0] != '!' && $package['platform'][$file] != $os) { $release[$releaseNum]['filelist']['ignore'][] = array( diff --git a/PEAR/PackageFile/v2/Validator.php b/PEAR/PackageFile/v2/Validator.php index 06109b641..506230838 100644 --- a/PEAR/PackageFile/v2/Validator.php +++ b/PEAR/PackageFile/v2/Validator.php @@ -1080,8 +1080,8 @@ function _validateFilelist($list = false, $allowignore = false, $dirs = '') foreach ($list['file'] as $i => $file) { if (isset($file['attribs']) && isset($file['attribs']['name'])) { - if ($file['attribs']['name']{0} == '.' && - $file['attribs']['name']{1} == '/') { + if ($file['attribs']['name'][0] == '.' && + $file['attribs']['name'][1] == '/') { // name is something like "./doc/whatever.txt" $this->_invalidFileName($file['attribs']['name'], $dirname); } diff --git a/PEAR/Registry.php b/PEAR/Registry.php index 61b756eb8..d97bbc076 100644 --- a/PEAR/Registry.php +++ b/PEAR/Registry.php @@ -2204,7 +2204,7 @@ function parsePackageName($param, $defaultchannel = 'pear.php.net') } if (!isset($components['scheme'])) { if (strpos($components['path'], '/') !== false) { - if ($components['path']{0} == '/') { + if ($components['path'][0] == '/') { return PEAR::raiseError('parsePackageName(): this is not ' . 'a package name, it begins with "/" in "' . $param . '"', 'invalid', null, null, $param); diff --git a/PEAR/Validate.php b/PEAR/Validate.php index 134fe17a3..683fd52db 100644 --- a/PEAR/Validate.php +++ b/PEAR/Validate.php @@ -287,7 +287,7 @@ function validateVersion() } if (!$this->_packagexml->getExtends()) { if ($versioncomponents[0] == '1') { - if ($versioncomponents[2]{0} == '0') { + if ($versioncomponents[2][0] == '0') { if ($versioncomponents[2] == '0') { // version 1.*.0000 $this->_addWarning('version', @@ -339,7 +339,7 @@ function validateVersion() return true; } if ($versioncomponents[0] == $majver) { - if ($versioncomponents[2]{0} == '0') { + if ($versioncomponents[2][0] == '0') { if ($versioncomponents[2] == '0') { // version 2.*.0000 $this->_addWarning('version', diff --git a/System.php b/System.php index d5b6a147d..338fe1d82 100644 --- a/System.php +++ b/System.php @@ -265,7 +265,7 @@ public static function mkDir($args) } elseif ($opt[0] == 'm') { // if the mode is clearly an octal number (starts with 0) // convert it to decimal - if (strlen($opt[1]) && $opt[1]{0} == '0') { + if (strlen($opt[1]) && $opt[1][0] == '0') { $opt[1] = octdec($opt[1]); } else { // convert to int