Skip to content

Commit 60ec76f

Browse files
authored
Merge pull request #84 from nikic/php8-compat
Fix PHP 8 compatibility issues
2 parents 50df63f + 25061ef commit 60ec76f

30 files changed

+92
-79
lines changed

PEAR/Command/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function getHelp($command)
193193
$help = $this->commands[$command]['summary'];
194194
}
195195

196-
if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
196+
if (preg_match_all('/{config\s+([^\}]+)}/', $help, $matches)) {
197197
foreach($matches[0] as $k => $v) {
198198
$help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
199199
}

PEAR/Command/Package.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ function doPackageDependencies($command, $options, $params)
872872
$deps = $info->getDependencies();
873873
$reg = &$this->config->getRegistry();
874874
if (is_array($deps)) {
875-
$d = new PEAR_Dependency2($this->config, array(), '');
876875
$data = array(
877876
'caption' => 'Dependencies for ' . $info->getPackage(),
878877
'border' => true,
@@ -929,7 +928,7 @@ function doPackageDependencies($command, $options, $params)
929928
if (isset($inf['conflicts'])) {
930929
$ver = 'conflicts';
931930
} else {
932-
$ver = $d->_getExtraString($inf);
931+
$ver = PEAR_Dependency2::_getExtraString($inf);
933932
}
934933

935934
$data['data'][] = array($req, ucfirst($deptype), $name,

PEAR/Command/Registry.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ function doInfo($command, $options, $params)
585585
case 'configure_options' : {
586586
foreach ($info[$key] as $i => $p) {
587587
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
588-
$info[$key][$i] = array_map(create_function('$a',
589-
'return join(" = ",$a);'), $info[$key][$i]);
588+
$info[$key][$i] = array_map(
589+
function($a) { return join(" = ", $a); },
590+
$info[$key][$i]);
590591
$info[$key][$i] = implode(', ', $info[$key][$i]);
591592
}
592593
$info[$key] = implode("\n", $info[$key]);

PEAR/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function setFrontendObject(&$ui)
304304
* @param boolean Determines whether to include $state in the list
305305
* @return false|array False if $state is not a valid release state
306306
*/
307-
function betterStates($state, $include = false)
307+
static function betterStates($state, $include = false)
308308
{
309309
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
310310
$i = array_search($state, $states);
@@ -718,7 +718,7 @@ function buildProvidesArray($srcinfo)
718718
* @return mixed
719719
* @access public
720720
*/
721-
function analyzeSourceCode($file)
721+
static function analyzeSourceCode($file)
722722
{
723723
if (!class_exists('PEAR_PackageFile_v2_Validator')) {
724724
require_once 'PEAR/PackageFile/v2/Validator.php';

PEAR/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2086,7 +2086,7 @@ function &getFTP()
20862086
return $a;
20872087
}
20882088

2089-
function _prependPath($path, $prepend)
2089+
static function _prependPath($path, $prepend)
20902090
{
20912091
if (strlen($prepend) > 0) {
20922092
if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {

PEAR/Dependency2.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function __construct(&$config, $installoptions, $package,
110110
$this->_currentPackage = $package;
111111
}
112112

113-
function _getExtraString($dep)
113+
static function _getExtraString($dep)
114114
{
115115
$extra = ' (';
116116
if (isset($dep['uri'])) {
@@ -337,7 +337,7 @@ function validateExtensionDependency($dep, $required = true)
337337
}
338338

339339
$loaded = $this->extension_loaded($dep['name']);
340-
$extra = $this->_getExtraString($dep);
340+
$extra = self::_getExtraString($dep);
341341
if (isset($dep['exclude'])) {
342342
if (!is_array($dep['exclude'])) {
343343
$dep['exclude'] = array($dep['exclude']);
@@ -486,7 +486,7 @@ function validatePhpDependency($dep)
486486
}
487487

488488
$version = $this->phpversion();
489-
$extra = $this->_getExtraString($dep);
489+
$extra = self::_getExtraString($dep);
490490
if (isset($dep['exclude'])) {
491491
if (!is_array($dep['exclude'])) {
492492
$dep['exclude'] = array($dep['exclude']);
@@ -546,7 +546,7 @@ function getPEARVersion()
546546
function validatePearinstallerDependency($dep)
547547
{
548548
$pearversion = $this->getPEARVersion();
549-
$extra = $this->_getExtraString($dep);
549+
$extra = self::_getExtraString($dep);
550550
if (isset($dep['exclude'])) {
551551
if (!is_array($dep['exclude'])) {
552552
$dep['exclude'] = array($dep['exclude']);
@@ -700,7 +700,7 @@ function _validatePackageDownload($dep, $required, $params, $depv1 = false)
700700
}
701701
}
702702

703-
$extra = $this->_getExtraString($dep);
703+
$extra = self::_getExtraString($dep);
704704
if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
705705
$dep['exclude'] = array($dep['exclude']);
706706
}
@@ -1098,7 +1098,7 @@ function _validatePackageUninstall($dep, $required, $dl)
10981098
return true;
10991099
}
11001100

1101-
$extra = $this->_getExtraString($dep);
1101+
$extra = self::_getExtraString($dep);
11021102
if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
11031103
$dep['exclude'] = array($dep['exclude']);
11041104
}
@@ -1232,7 +1232,7 @@ function validateDependency1($dep, $params = array())
12321232
$dep['optional'] = 'no';
12331233
}
12341234

1235-
list($newdep, $type) = $this->normalizeDep($dep);
1235+
list($newdep, $type) = self::normalizeDep($dep);
12361236
if (!$newdep) {
12371237
return $this->raiseError("Invalid Dependency");
12381238
}
@@ -1246,7 +1246,7 @@ function validateDependency1($dep, $params = array())
12461246
/**
12471247
* Convert a 1.0 dep into a 2.0 dep
12481248
*/
1249-
function normalizeDep($dep)
1249+
static function normalizeDep($dep)
12501250
{
12511251
$types = array(
12521252
'pkg' => 'Package',
@@ -1325,7 +1325,7 @@ function normalizeDep($dep)
13251325
* @param string Operator
13261326
* @return string Sign equivalent
13271327
*/
1328-
function signOperator($operator)
1328+
static function signOperator($operator)
13291329
{
13301330
switch($operator) {
13311331
case 'lt': return '<';

PEAR/Downloader.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function __construct($ui = null, $options = array(), $config = null)
185185
if (!count($unused)) {
186186
continue;
187187
}
188-
$strtolower = create_function('$a','return strtolower($a);');
188+
$strtolower = function($a) { return strtolower($a); };
189189
array_walk($this->_installed[$key], $strtolower);
190190
}
191191
}
@@ -1712,7 +1712,8 @@ public static function _downloadHttp(
17121712
if (!$wp = @fopen($dest_file, 'wb')) {
17131713
fclose($fp);
17141714
if ($callback) {
1715-
call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
1715+
call_user_func($callback, 'writefailed',
1716+
array($dest_file, error_get_last()["message"]));
17161717
}
17171718
return PEAR::raiseError("could not open $dest_file for writing");
17181719
}
@@ -1732,9 +1733,11 @@ public static function _downloadHttp(
17321733
if (!@fwrite($wp, $data)) {
17331734
fclose($fp);
17341735
if ($callback) {
1735-
call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
1736+
call_user_func($callback, 'writefailed',
1737+
array($dest_file, error_get_last()["message"]));
17361738
}
1737-
return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
1739+
return PEAR::raiseError(
1740+
"$dest_file: write failed (" . error_get_last()["message"] . ")");
17381741
}
17391742
}
17401743

PEAR/ErrorStack.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ function pop()
676676
* @return boolean
677677
* @since PEAR1.5.0a1
678678
*/
679-
function staticPop($package)
679+
static function staticPop($package)
680680
{
681681
if ($package) {
682682
if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {

PEAR/Installer.php

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ function _installFile($file, $atts, $tmp_path, $options)
323323
}
324324

325325
if (!@copy($orig_file, $dest_file)) {
326-
return $this->raiseError("failed to write $dest_file: $php_errormsg",
327-
PEAR_INSTALLER_FAILED);
326+
return $this->raiseError(
327+
"failed to write $dest_file: " . error_get_last()["message"],
328+
PEAR_INSTALLER_FAILED);
328329
}
329330

330331
$this->log(3, "+ cp $orig_file $dest_file");
@@ -399,13 +400,15 @@ function _installFile($file, $atts, $tmp_path, $options)
399400

400401
$wp = @fopen($dest_file, "wb");
401402
if (!is_resource($wp)) {
402-
return $this->raiseError("failed to create $dest_file: $php_errormsg",
403-
PEAR_INSTALLER_FAILED);
403+
return $this->raiseError(
404+
"failed to create $dest_file: " . error_get_last()["message"],
405+
PEAR_INSTALLER_FAILED);
404406
}
405407

406408
if (@fwrite($wp, $contents) === false) {
407-
return $this->raiseError("failed writing to $dest_file: $php_errormsg",
408-
PEAR_INSTALLER_FAILED);
409+
return $this->raiseError(
410+
"failed writing to $dest_file: " . error_get_last()["message"],
411+
PEAR_INSTALLER_FAILED);
409412
}
410413

411414
fclose($wp);
@@ -452,7 +455,8 @@ function _installFile($file, $atts, $tmp_path, $options)
452455
$this->addFileOperation("chmod", array($mode, $dest_file));
453456
if (!@chmod($dest_file, $mode)) {
454457
if (!isset($options['soft'])) {
455-
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
458+
$this->log(0, "failed to change mode of $dest_file: " .
459+
error_get_last()["message"]);
456460
}
457461
}
458462
}
@@ -562,8 +566,9 @@ function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
562566
}
563567

564568
if (!@copy($orig_file, $dest_file)) {
565-
return $this->raiseError("failed to write $dest_file: $php_errormsg",
566-
PEAR_INSTALLER_FAILED);
569+
return $this->raiseError(
570+
"failed to write $dest_file: " . error_get_last()["message"],
571+
PEAR_INSTALLER_FAILED);
567572
}
568573

569574
$this->log(3, "+ cp $orig_file $dest_file");
@@ -605,13 +610,15 @@ function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
605610

606611
$wp = @fopen($dest_file, "wb");
607612
if (!is_resource($wp)) {
608-
return $this->raiseError("failed to create $dest_file: $php_errormsg",
609-
PEAR_INSTALLER_FAILED);
613+
return $this->raiseError(
614+
"failed to create $dest_file: " . error_get_last()["message"],
615+
PEAR_INSTALLER_FAILED);
610616
}
611617

612618
if (fwrite($wp, $contents) === false) {
613-
return $this->raiseError("failed writing to $dest_file: $php_errormsg",
614-
PEAR_INSTALLER_FAILED);
619+
return $this->raiseError(
620+
"failed writing to $dest_file: " . error_get_last()["message"],
621+
PEAR_INSTALLER_FAILED);
615622
}
616623

617624
fclose($wp);
@@ -667,7 +674,8 @@ function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
667674
$this->addFileOperation("chmod", array($mode, $dest_file));
668675
if (!@chmod($dest_file, $mode)) {
669676
if (!isset($options['soft'])) {
670-
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
677+
$this->log(0, "failed to change mode of $dest_file: " .
678+
error_get_last()["message"]);
671679
}
672680
}
673681
}
@@ -854,7 +862,7 @@ function commitFileTransaction()
854862

855863
if (!@copy($data[0], $data[0] . '.bak')) {
856864
$this->log(1, 'Could not copy ' . $data[0] . ' to ' . $data[0] .
857-
'.bak ' . $php_errormsg);
865+
'.bak ' . error_get_last()["message"]);
858866
return false;
859867
}
860868
$this->log(3, "+ backup $data[0] to $data[0].bak");
@@ -889,7 +897,7 @@ function commitFileTransaction()
889897
$perms = @fileperms($data[0]);
890898
if (!@copy($data[0], $data[1])) {
891899
$this->log(1, 'Could not rename ' . $data[0] . ' to ' . $data[1] .
892-
' ' . $php_errormsg);
900+
' ' . error_get_last()["message"]);
893901
return false;
894902
}
895903

@@ -901,7 +909,7 @@ function commitFileTransaction()
901909
case 'chmod':
902910
if (!@chmod($data[1], $data[0])) {
903911
$this->log(1, 'Could not chmod ' . $data[1] . ' to ' .
904-
decoct($data[0]) . ' ' . $php_errormsg);
912+
decoct($data[0]) . ' ' . error_get_last()["message"]);
905913
return false;
906914
}
907915

@@ -912,7 +920,7 @@ function commitFileTransaction()
912920
if (file_exists($data[0])) {
913921
if (!@unlink($data[0])) {
914922
$this->log(1, 'Could not delete ' . $data[0] . ' ' .
915-
$php_errormsg);
923+
error_get_last()["message"]);
916924
return false;
917925
}
918926
$this->log(3, "+ rm $data[0]");
@@ -934,7 +942,7 @@ function commitFileTransaction()
934942
closedir($testme);
935943
if (!@rmdir($data[0])) {
936944
$this->log(1, 'Could not rmdir ' . $data[0] . ' ' .
937-
$php_errormsg);
945+
error_get_last()["message"]);
938946
return false;
939947
}
940948
$this->log(3, "+ rmdir $data[0]");
@@ -1553,7 +1561,9 @@ function _compileSourceFiles($savechannel, &$filelist)
15531561
}
15541562

15551563
if (!@copy($ext['file'], $copyto)) {
1556-
return $this->raiseError("failed to write $copyto ($php_errormsg)", PEAR_INSTALLER_FAILED);
1564+
return $this->raiseError(
1565+
"failed to write $copyto (" . error_get_last()["message"] . ")",
1566+
PEAR_INSTALLER_FAILED);
15571567
}
15581568

15591569
$this->log(3, "+ cp $ext[file] $copyto");
@@ -1562,7 +1572,8 @@ function _compileSourceFiles($savechannel, &$filelist)
15621572
$mode = 0666 & ~(int)octdec($this->config->get('umask'));
15631573
$this->addFileOperation('chmod', array($mode, $copyto));
15641574
if (!@chmod($copyto, $mode)) {
1565-
$this->log(0, "failed to change mode of $copyto ($php_errormsg)");
1575+
$this->log(0, "failed to change mode of $copyto (" .
1576+
error_get_last()["message"] . ")");
15661577
}
15671578
}
15681579
}

PEAR/PackageFile/v1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,8 @@ function _analyzeSourceCode($file)
14201420
}
14211421
}
14221422
switch ($token) {
1423-
case T_WHITESPACE :
1424-
continue;
1423+
case T_WHITESPACE:
1424+
break;
14251425
case ';':
14261426
if ($interface) {
14271427
$current_function = '';

0 commit comments

Comments
 (0)