Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8 compatibility issues #84

Merged
merged 26 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
35be713
Remove $vars argument from error handler
nikic Feb 7, 2019
446bda9
Remove track_errors=1 ini option
nikic Feb 7, 2019
de70ed8
Replace continue in switch with break
nikic Feb 7, 2019
47d80e3
Make test_PEAR_Dependency2::singleton() method static
nikic Feb 7, 2019
2af2980
Remove /e flag in preg_match_all
nikic Feb 7, 2019
bf07026
Make PEAR_Common::betterStates() static
nikic Feb 7, 2019
72d3c6f
Remove use of create_function in PEAR Registry
nikic Feb 7, 2019
1488617
Make PEAR_Dependency2::normalizeDep() static
nikic Feb 7, 2019
550c0a6
Also make PEAR_Dependency2::signOperator() static
nikic Feb 7, 2019
585246e
Make PEAR_Dependency2::_getExtraString() static
nikic Feb 7, 2019
b8d5595
Remove create_function() use in PEAR_Downloader
nikic Feb 7, 2019
5aa5e9c
Call method on instance in test
nikic Feb 7, 2019
87896ef
Make PEAR_ErrorStack::staticPop() static
nikic Feb 7, 2019
3b7d55b
Remove uses of create_function in PackageFile_v2
nikic Feb 7, 2019
b3db06d
Remove create_function use in Command_Registry
nikic Feb 7, 2019
7cf175f
Remove create_function() use in phpt_test
nikic Feb 7, 2019
553b7a2
Make PEAR_Config::_prependPath() static
nikic Feb 7, 2019
8c5f6ae
Remove error handler $vars in test
nikic Feb 7, 2019
ac4abec
Make some test methods static
nikic Feb 7, 2019
7a8ac62
Migrate PEAR_Installer away from $php_errormsg
nikic Feb 7, 2019
9d48b4c
Migrate PEAR_Downloader away from php_errormsg
nikic Feb 7, 2019
793f0f8
Make fakeHandleError() method in test static
nikic Feb 7, 2019
5d4ffa0
Switch fake_log to use __construct
nikic Feb 7, 2019
d9916ac
Make PEAR_Common::analyzeSourceCode() static
nikic Feb 7, 2019
eb357e4
Don't use create_function() in tests
nikic Feb 7, 2019
25061ef
Mark some functions as static in tests
nikic Feb 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PEAR/Command/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function getHelp($command)
$help = $this->commands[$command]['summary'];
}

if (preg_match_all('/{config\s+([^\}]+)}/e', $help, $matches)) {
if (preg_match_all('/{config\s+([^\}]+)}/', $help, $matches)) {
foreach($matches[0] as $k => $v) {
$help = preg_replace("/$v/", $config->get($matches[1][$k]), $help);
}
Expand Down
3 changes: 1 addition & 2 deletions PEAR/Command/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ function doPackageDependencies($command, $options, $params)
$deps = $info->getDependencies();
$reg = &$this->config->getRegistry();
if (is_array($deps)) {
$d = new PEAR_Dependency2($this->config, array(), '');
$data = array(
'caption' => 'Dependencies for ' . $info->getPackage(),
'border' => true,
Expand Down Expand Up @@ -929,7 +928,7 @@ function doPackageDependencies($command, $options, $params)
if (isset($inf['conflicts'])) {
$ver = 'conflicts';
} else {
$ver = $d->_getExtraString($inf);
$ver = PEAR_Dependency2::_getExtraString($inf);
}

$data['data'][] = array($req, ucfirst($deptype), $name,
Expand Down
5 changes: 3 additions & 2 deletions PEAR/Command/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,9 @@ function doInfo($command, $options, $params)
case 'configure_options' : {
foreach ($info[$key] as $i => $p) {
$info[$key][$i] = array_map(null, array_keys($p), array_values($p));
$info[$key][$i] = array_map(create_function('$a',
'return join(" = ",$a);'), $info[$key][$i]);
$info[$key][$i] = array_map(
function($a) { return join(" = ", $a); },
$info[$key][$i]);
$info[$key][$i] = implode(', ', $info[$key][$i]);
}
$info[$key] = implode("\n", $info[$key]);
Expand Down
4 changes: 2 additions & 2 deletions PEAR/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function setFrontendObject(&$ui)
* @param boolean Determines whether to include $state in the list
* @return false|array False if $state is not a valid release state
*/
function betterStates($state, $include = false)
static function betterStates($state, $include = false)
{
static $states = array('snapshot', 'devel', 'alpha', 'beta', 'stable');
$i = array_search($state, $states);
Expand Down Expand Up @@ -718,7 +718,7 @@ function buildProvidesArray($srcinfo)
* @return mixed
* @access public
*/
function analyzeSourceCode($file)
static function analyzeSourceCode($file)
{
if (!class_exists('PEAR_PackageFile_v2_Validator')) {
require_once 'PEAR/PackageFile/v2/Validator.php';
Expand Down
2 changes: 1 addition & 1 deletion PEAR/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,7 @@ function &getFTP()
return $a;
}

function _prependPath($path, $prepend)
static function _prependPath($path, $prepend)
{
if (strlen($prepend) > 0) {
if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
Expand Down
18 changes: 9 additions & 9 deletions PEAR/Dependency2.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function __construct(&$config, $installoptions, $package,
$this->_currentPackage = $package;
}

function _getExtraString($dep)
static function _getExtraString($dep)
{
$extra = ' (';
if (isset($dep['uri'])) {
Expand Down Expand Up @@ -337,7 +337,7 @@ function validateExtensionDependency($dep, $required = true)
}

$loaded = $this->extension_loaded($dep['name']);
$extra = $this->_getExtraString($dep);
$extra = self::_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
Expand Down Expand Up @@ -486,7 +486,7 @@ function validatePhpDependency($dep)
}

$version = $this->phpversion();
$extra = $this->_getExtraString($dep);
$extra = self::_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
Expand Down Expand Up @@ -546,7 +546,7 @@ function getPEARVersion()
function validatePearinstallerDependency($dep)
{
$pearversion = $this->getPEARVersion();
$extra = $this->_getExtraString($dep);
$extra = self::_getExtraString($dep);
if (isset($dep['exclude'])) {
if (!is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
Expand Down Expand Up @@ -700,7 +700,7 @@ function _validatePackageDownload($dep, $required, $params, $depv1 = false)
}
}

$extra = $this->_getExtraString($dep);
$extra = self::_getExtraString($dep);
if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ function _validatePackageUninstall($dep, $required, $dl)
return true;
}

$extra = $this->_getExtraString($dep);
$extra = self::_getExtraString($dep);
if (isset($dep['exclude']) && !is_array($dep['exclude'])) {
$dep['exclude'] = array($dep['exclude']);
}
Expand Down Expand Up @@ -1232,7 +1232,7 @@ function validateDependency1($dep, $params = array())
$dep['optional'] = 'no';
}

list($newdep, $type) = $this->normalizeDep($dep);
list($newdep, $type) = self::normalizeDep($dep);
if (!$newdep) {
return $this->raiseError("Invalid Dependency");
}
Expand All @@ -1246,7 +1246,7 @@ function validateDependency1($dep, $params = array())
/**
* Convert a 1.0 dep into a 2.0 dep
*/
function normalizeDep($dep)
static function normalizeDep($dep)
{
$types = array(
'pkg' => 'Package',
Expand Down Expand Up @@ -1325,7 +1325,7 @@ function normalizeDep($dep)
* @param string Operator
* @return string Sign equivalent
*/
function signOperator($operator)
static function signOperator($operator)
{
switch($operator) {
case 'lt': return '<';
Expand Down
11 changes: 7 additions & 4 deletions PEAR/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function __construct($ui = null, $options = array(), $config = null)
if (!count($unused)) {
continue;
}
$strtolower = create_function('$a','return strtolower($a);');
$strtolower = function($a) { return strtolower($a); };
array_walk($this->_installed[$key], $strtolower);
}
}
Expand Down Expand Up @@ -1712,7 +1712,8 @@ public static function _downloadHttp(
if (!$wp = @fopen($dest_file, 'wb')) {
fclose($fp);
if ($callback) {
call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
call_user_func($callback, 'writefailed',
array($dest_file, error_get_last()["message"]));
}
return PEAR::raiseError("could not open $dest_file for writing");
}
Expand All @@ -1732,9 +1733,11 @@ public static function _downloadHttp(
if (!@fwrite($wp, $data)) {
fclose($fp);
if ($callback) {
call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
call_user_func($callback, 'writefailed',
array($dest_file, error_get_last()["message"]));
}
return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
return PEAR::raiseError(
"$dest_file: write failed (" . error_get_last()["message"] . ")");
}
}

Expand Down
2 changes: 1 addition & 1 deletion PEAR/ErrorStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ function pop()
* @return boolean
* @since PEAR1.5.0a1
*/
function staticPop($package)
static function staticPop($package)
{
if ($package) {
if (!isset($GLOBALS['_PEAR_ERRORSTACK_SINGLETON'][$package])) {
Expand Down
53 changes: 32 additions & 21 deletions PEAR/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ function _installFile($file, $atts, $tmp_path, $options)
}

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

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

$wp = @fopen($dest_file, "wb");
if (!is_resource($wp)) {
return $this->raiseError("failed to create $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
return $this->raiseError(
"failed to create $dest_file: " . error_get_last()["message"],
PEAR_INSTALLER_FAILED);
}

if (@fwrite($wp, $contents) === false) {
return $this->raiseError("failed writing to $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
return $this->raiseError(
"failed writing to $dest_file: " . error_get_last()["message"],
PEAR_INSTALLER_FAILED);
}

fclose($wp);
Expand Down Expand Up @@ -452,7 +455,8 @@ function _installFile($file, $atts, $tmp_path, $options)
$this->addFileOperation("chmod", array($mode, $dest_file));
if (!@chmod($dest_file, $mode)) {
if (!isset($options['soft'])) {
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
$this->log(0, "failed to change mode of $dest_file: " .
error_get_last()["message"]);
}
}
}
Expand Down Expand Up @@ -562,8 +566,9 @@ function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
}

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

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

$wp = @fopen($dest_file, "wb");
if (!is_resource($wp)) {
return $this->raiseError("failed to create $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
return $this->raiseError(
"failed to create $dest_file: " . error_get_last()["message"],
PEAR_INSTALLER_FAILED);
}

if (fwrite($wp, $contents) === false) {
return $this->raiseError("failed writing to $dest_file: $php_errormsg",
PEAR_INSTALLER_FAILED);
return $this->raiseError(
"failed writing to $dest_file: " . error_get_last()["message"],
PEAR_INSTALLER_FAILED);
}

fclose($wp);
Expand Down Expand Up @@ -667,7 +674,8 @@ function _installFile2(&$pkg, $file, &$real_atts, $tmp_path, $options)
$this->addFileOperation("chmod", array($mode, $dest_file));
if (!@chmod($dest_file, $mode)) {
if (!isset($options['soft'])) {
$this->log(0, "failed to change mode of $dest_file: $php_errormsg");
$this->log(0, "failed to change mode of $dest_file: " .
error_get_last()["message"]);
}
}
}
Expand Down Expand Up @@ -854,7 +862,7 @@ function commitFileTransaction()

if (!@copy($data[0], $data[0] . '.bak')) {
$this->log(1, 'Could not copy ' . $data[0] . ' to ' . $data[0] .
'.bak ' . $php_errormsg);
'.bak ' . error_get_last()["message"]);
return false;
}
$this->log(3, "+ backup $data[0] to $data[0].bak");
Expand Down Expand Up @@ -889,7 +897,7 @@ function commitFileTransaction()
$perms = @fileperms($data[0]);
if (!@copy($data[0], $data[1])) {
$this->log(1, 'Could not rename ' . $data[0] . ' to ' . $data[1] .
' ' . $php_errormsg);
' ' . error_get_last()["message"]);
return false;
}

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

Expand All @@ -912,7 +920,7 @@ function commitFileTransaction()
if (file_exists($data[0])) {
if (!@unlink($data[0])) {
$this->log(1, 'Could not delete ' . $data[0] . ' ' .
$php_errormsg);
error_get_last()["message"]);
return false;
}
$this->log(3, "+ rm $data[0]");
Expand All @@ -934,7 +942,7 @@ function commitFileTransaction()
closedir($testme);
if (!@rmdir($data[0])) {
$this->log(1, 'Could not rmdir ' . $data[0] . ' ' .
$php_errormsg);
error_get_last()["message"]);
return false;
}
$this->log(3, "+ rmdir $data[0]");
Expand Down Expand Up @@ -1553,7 +1561,9 @@ function _compileSourceFiles($savechannel, &$filelist)
}

if (!@copy($ext['file'], $copyto)) {
return $this->raiseError("failed to write $copyto ($php_errormsg)", PEAR_INSTALLER_FAILED);
return $this->raiseError(
"failed to write $copyto (" . error_get_last()["message"] . ")",
PEAR_INSTALLER_FAILED);
}

$this->log(3, "+ cp $ext[file] $copyto");
Expand All @@ -1562,7 +1572,8 @@ function _compileSourceFiles($savechannel, &$filelist)
$mode = 0666 & ~(int)octdec($this->config->get('umask'));
$this->addFileOperation('chmod', array($mode, $copyto));
if (!@chmod($copyto, $mode)) {
$this->log(0, "failed to change mode of $copyto ($php_errormsg)");
$this->log(0, "failed to change mode of $copyto (" .
error_get_last()["message"] . ")");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions PEAR/PackageFile/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,8 @@ function _analyzeSourceCode($file)
}
}
switch ($token) {
case T_WHITESPACE :
continue;
case T_WHITESPACE:
break;
case ';':
if ($interface) {
$current_function = '';
Expand Down
4 changes: 2 additions & 2 deletions PEAR/PackageFile/v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,12 @@ function _differentName($handle, $name, $selfname)
function _unmatchedMaintainers($my, $yours)
{
if ($my) {
array_walk($my, create_function('&$i, $k', '$i = $i["handle"];'));
array_walk($my, function(&$i, $k) { $i = $i["handle"]; });
$this->_stack->push(__FUNCTION__, 'error', array('handles' => $my),
'package.xml 2.0 has unmatched extra maintainers "%handles%"');
}
if ($yours) {
array_walk($yours, create_function('&$i, $k', '$i = $i["handle"];'));
array_walk($yours, function(&$i, $k) { $i = $i["handle"]; });
$this->_stack->push(__FUNCTION__, 'error', array('handles' => $yours),
'package.xml 1.0 has unmatched extra maintainers "%handles%"');
}
Expand Down
2 changes: 1 addition & 1 deletion PEAR/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ function checkFileMap($path, $package = false, $api = '1.0', $attrs = false)
if (!class_exists('PEAR_Installer_Role')) {
require_once 'PEAR/Installer/Role.php';
}
$notempty = create_function('$a','return !empty($a);');
$notempty = function($a) { return !empty($a); };
}
$package = is_array($package) ? array(strtolower($package[0]), strtolower($package[1]))
: strtolower($package);
Expand Down
1 change: 0 additions & 1 deletion PEAR/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class PEAR_RunTest
'display_errors=1',
'log_errors=0',
'html_errors=0',
'track_errors=1',
'report_memleaks=0',
'report_zend_debug=0',
'docref_root=',
Expand Down
3 changes: 1 addition & 2 deletions scripts/pearcmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,11 @@ function cmdHelp($command)
* @param mixed $errmsg Message
* @param mixed $file Filename
* @param mixed $line Line number
* @param mixed $vars Variables
*
* @access public
* @return boolean
*/
function error_handler($errno, $errmsg, $file, $line, $vars)
function error_handler($errno, $errmsg, $file, $line)
{
if ($errno & E_STRICT
|| $errno & E_DEPRECATED
Expand Down
Loading