Skip to content

Commit 212dcfe

Browse files
claudef3l1x
authored andcommitted
Remove deprecated $HTTP_SERVER_VARS global variable
$HTTP_SERVER_VARS was deprecated in PHP 5.3 and removed in PHP 5.4. Replace all usages with $_SERVER superglobal and simplify the code by removing the unnecessary fallback branches. Fixes #66
1 parent 2e5de3c commit 212dcfe

File tree

1 file changed

+9
-96
lines changed

1 file changed

+9
-96
lines changed

src/nusoap.php

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,16 +3741,12 @@ function __construct($wsdl = false)
37413741
parent::__construct();
37423742
// turn on debugging?
37433743
global $debug;
3744-
global $HTTP_SERVER_VARS;
37453744

37463745
if (isset($_SERVER)) {
37473746
$this->debug("_SERVER is defined:");
37483747
$this->appendDebug($this->varDump($_SERVER));
3749-
} elseif (isset($HTTP_SERVER_VARS)) {
3750-
$this->debug("HTTP_SERVER_VARS is defined:");
3751-
$this->appendDebug($this->varDump($HTTP_SERVER_VARS));
37523748
} else {
3753-
$this->debug("Neither _SERVER nor HTTP_SERVER_VARS is defined.");
3749+
$this->debug("_SERVER is not defined.");
37543750
}
37553751

37563752
if (isset($debug)) {
@@ -3760,15 +3756,7 @@ function __construct($wsdl = false)
37603756
$qs = explode('&', $_SERVER['QUERY_STRING']);
37613757
foreach ($qs as $v) {
37623758
if (substr($v, 0, 6) == 'debug=') {
3763-
$this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #1");
3764-
$this->debug_flag = substr($v, 6);
3765-
}
3766-
}
3767-
} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3768-
$qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
3769-
foreach ($qs as $v) {
3770-
if (substr($v, 0, 6) == 'debug=') {
3771-
$this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #2");
3759+
$this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string");
37723760
$this->debug_flag = substr($v, 6);
37733761
}
37743762
}
@@ -3802,23 +3790,8 @@ function __construct($wsdl = false)
38023790
*/
38033791
function service($data)
38043792
{
3805-
global $HTTP_SERVER_VARS;
3806-
3807-
if (isset($_SERVER['REQUEST_METHOD'])) {
3808-
$rm = $_SERVER['REQUEST_METHOD'];
3809-
} elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
3810-
$rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
3811-
} else {
3812-
$rm = '';
3813-
}
3814-
3815-
if (isset($_SERVER['QUERY_STRING'])) {
3816-
$qs = $_SERVER['QUERY_STRING'];
3817-
} elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
3818-
$qs = $HTTP_SERVER_VARS['QUERY_STRING'];
3819-
} else {
3820-
$qs = '';
3821-
}
3793+
$rm = $_SERVER['REQUEST_METHOD'] ?? '';
3794+
$qs = $_SERVER['QUERY_STRING'] ?? '';
38223795
$this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
38233796

38243797
if ($rm == 'POST') {
@@ -3881,8 +3854,6 @@ function service($data)
38813854
*/
38823855
function parse_http_headers()
38833856
{
3884-
global $HTTP_SERVER_VARS;
3885-
38863857
$this->request = '';
38873858
$this->SOAPAction = '';
38883859
if (function_exists('getallheaders')) {
@@ -3949,42 +3920,6 @@ function parse_http_headers()
39493920
$this->debug("$k: $v");
39503921
}
39513922
}
3952-
} elseif (is_array($HTTP_SERVER_VARS)) {
3953-
$this->debug("In parse_http_headers, use HTTP_SERVER_VARS");
3954-
foreach ($HTTP_SERVER_VARS as $k => $v) {
3955-
if (substr($k, 0, 5) == 'HTTP_') {
3956-
$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
3957-
$k = strtolower(substr($k, 5));
3958-
} else {
3959-
$k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
3960-
$k = strtolower($k);
3961-
}
3962-
if ($k == 'soapaction') {
3963-
// get SOAPAction header
3964-
$k = 'SOAPAction';
3965-
$v = str_replace('"', '', $v);
3966-
$v = str_replace('\\', '', $v);
3967-
$this->SOAPAction = $v;
3968-
} elseif ($k == 'content-type') {
3969-
// get the character encoding of the incoming request
3970-
if (strpos($v, '=')) {
3971-
$enc = substr(strstr($v, '='), 1);
3972-
$enc = str_replace('"', '', $enc);
3973-
$enc = str_replace('\\', '', $enc);
3974-
if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i', $enc)) {
3975-
$this->xml_encoding = strtoupper($enc);
3976-
} else {
3977-
$this->xml_encoding = 'US-ASCII';
3978-
}
3979-
} else {
3980-
// should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
3981-
$this->xml_encoding = 'ISO-8859-1';
3982-
}
3983-
}
3984-
$this->headers[$k] = $v;
3985-
$this->request .= "$k: $v\r\n";
3986-
$this->debug("$k: $v");
3987-
}
39883923
} else {
39893924
$this->debug("In parse_http_headers, HTTP headers not accessible");
39903925
$this->setError("HTTP headers not accessible");
@@ -4551,8 +4486,6 @@ function add_to_map($methodname, $in, $out)
45514486
*/
45524487
function register($name, $in = array(), $out = array(), $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '', $customResponseTagName = '')
45534488
{
4554-
global $HTTP_SERVER_VARS;
4555-
45564489
if ($this->externalWSDLURL) {
45574490
die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
45584491
}
@@ -4569,13 +4502,9 @@ function register($name, $in = array(), $out = array(), $namespace = false, $soa
45694502
if (isset($_SERVER)) {
45704503
$SERVER_NAME = $_SERVER['SERVER_NAME'];
45714504
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
4572-
$HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4573-
} elseif (isset($HTTP_SERVER_VARS)) {
4574-
$SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4575-
$SCRIPT_NAME = $HTTP_SERVER_VARS['SCRIPT_NAME'];
4576-
$HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4505+
$HTTPS = $_SERVER['HTTPS'] ?? 'off';
45774506
} else {
4578-
$this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4507+
$this->setError("_SERVER is not available");
45794508
$HTTPS = '';
45804509
$SERVER_NAME = '';
45814510
$SCRIPT_NAME = '';
@@ -4647,20 +4576,13 @@ function fault($faultcode, $faultstring, $faultactor = '', $faultdetail = '')
46474576
*/
46484577
function configureWSDL($serviceName, $namespace = false, $endpoint = false, $style = 'rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
46494578
{
4650-
global $HTTP_SERVER_VARS;
4651-
46524579
if (isset($_SERVER['SERVER_NAME'])) {
46534580
$SERVER_NAME = $_SERVER['SERVER_NAME'];
46544581
$SERVER_PORT = $_SERVER['SERVER_PORT'];
46554582
$SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
4656-
$HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
4657-
} elseif (isset($HTTP_SERVER_VARS)) {
4658-
$SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
4659-
$SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
4660-
$SCRIPT_NAME = $HTTP_SERVER_VARS['SCRIPT_NAME'];
4661-
$HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
4583+
$HTTPS = $_SERVER['HTTPS'] ?? 'off';
46624584
} else {
4663-
$this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
4585+
$this->setError("_SERVER is not available");
46644586
$SERVER_PORT = '';
46654587
$SERVER_NAME = '';
46664588
$SCRIPT_NAME = '';
@@ -5510,16 +5432,7 @@ function getTypeDef($type, $ns)
55105432
*/
55115433
function webDescription()
55125434
{
5513-
global $HTTP_SERVER_VARS;
5514-
5515-
if (isset($_SERVER)) {
5516-
$PHP_SELF = $_SERVER['PHP_SELF'];
5517-
} elseif (isset($HTTP_SERVER_VARS)) {
5518-
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
5519-
} else {
5520-
$this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
5521-
$PHP_SELF = '';
5522-
}
5435+
$PHP_SELF = $_SERVER['PHP_SELF'] ?? '';
55235436

55245437
$b = '<!DOCTYPE html>
55255438
<html><head><title>NuSOAP: ' . $this->serviceName . '</title>

0 commit comments

Comments
 (0)