Issues (209)

samples/wsdlclient4.php (7 issues)

1
<?php
2
/*
3
 *	$Id: wsdlclient4.php,v 1.6 2005/05/12 21:42:06 snichol Exp $
4
 *
5
 *	WSDL client sample, based on soap builders round 2 interop.
6
 *
7
 *	Service: WSDL
8
 *	Payload: rpc/encoded
9
 *	Transport: http
10
 *	Authentication: none
11
 */
12
require_once('../lib/nusoap.php');
13
/*
14
 *	Grab post vars, if present
15
 */
16
$method = isset($_POST['method']) ? $_POST['method'] : '';
17
$null = isset($_POST['null']) ? $_POST['null'] : '';
18
$empty = isset($_POST['empty']) ? $_POST['empty'] : '';
19
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
20
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
21
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
22
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
23
/*
24
 *	When no method has been specified, give the user a choice
25
 */
26
if ($method == '') {
27
	echo '<form name="MethodForm" method="POST">';
28
	echo '<input type="hidden" name="proxyhost" value="' . $proxyhost .'">';
29
	echo '<input type="hidden" name="proxyport" value="' . $proxyport .'">';
30
	echo '<input type="hidden" name="proxyusername" value="' . $proxyusername .'">';
31
	echo '<input type="hidden" name="proxypassword" value="' . $proxypassword .'">';
32
	echo 'Method: <select name="method">';
33
	echo '<option>echoString</option>';
34
	echo '<option>echoStringArray</option>';
35
	echo '<option>echoInteger</option>';
36
	echo '<option>echoIntegerArray</option>';
37
	echo '<option>echoFloat</option>';
38
	echo '<option>echoFloatArray</option>';
39
	echo '<option>echoStruct</option>';
40
	echo '<option>echoStructArray</option>';
41
	echo '<option>echoVoid</option>';
42
	echo '<option>echoBoolean</option>';
43
	echo '<option>echoBase64</option>';
44
	echo '</select><br><br>';
45
	echo 'Null parameter? <input type="checkbox" name="null" value="1"><br>';
46
	echo 'Empty array? <input type="checkbox" name="empty" value="1"><br><br>';
47
	echo '<input type="submit" value="&#160;Execute&#160;">';
48
	echo '</form>';
49
	exit();
50
}
51
/*
52
 *	Execute the specified method
53
 */
54
if ($method == 'echoString') {
55
	if ($null != '1') {
56
		$params = array('inputString' => 'If you cannot echo a string, you probably cannot do much');
57
	} else {
58
		$params = array('inputString' => null);
59
	}
60
} elseif ($method == 'echoStringArray') {
61
	if ($null != '1') {
62
		if ($empty != '1') {
63
			$params = array('inputStringArray' => array('String 1', 'String 2', 'String Three'));
64
		} else {
65
			$params = array('inputStringArray' => array());
66
		}
67
	} else {
68
		$params = array('inputStringArray' => null);
69
	}
70
} elseif ($method == 'echoInteger') {
71
	if ($null != '1') {
72
		$params = array('inputInteger' => 329);
73
	} else {
74
		$params = array('inputInteger' => null);
75
	}
76
} elseif ($method == 'echoIntegerArray') {
77
	if ($null != '1') {
78
		if ($empty != '1') {
79
			$params = array('inputIntegerArray' => array(451, 43, -392220011, 1, 1, 2, 3, 5, 8, 13, 21));
80
		} else {
81
			$params = array('inputIntegerArray' => array());
82
		}
83
	} else {
84
		$params = array('inputIntegerArray' => null);
85
	}
86
} elseif ($method == 'echoFloat') {
87
	if ($null != '1') {
88
		$params = array('inputFloat' => 3.14159265);
89
	} else {
90
		$params = array('inputFloat' => null);
91
	}
92
} elseif ($method == 'echoFloatArray') {
93
	if ($null != '1') {
94
		if ($empty != '1') {
95
			$params = array('inputFloatArray' => array(1.1, 2.2, 3.3, 1/4, -1/9));
96
		} else {
97
			$params = array('inputFloatArray' => array());
98
		}
99
	} else {
100
		$params = array('inputFloatArray' => null);
101
	}
102
} elseif ($method == 'echoStruct') {
103
	if ($null != '1') {
104
		$struct = array('varString' => 'who', 'varInt' => 2, 'varFloat' => 3.14159);
105
		$params = array('inputStruct' => $struct);
106
	} else {
107
		$params = array('inputStruct' => null);
108
	}
109
} elseif ($method == 'echoStructArray') {
110
	if ($null != '1') {
111
		if ($empty != '1') {
112
			$structs[] = array('varString' => 'who', 'varInt' => 2, 'varFloat' => 3.14159);
113
			$structs[] = array('varString' => 'when', 'varInt' => 4, 'varFloat' => 99.9876);
114
			$params = array('inputStructArray' => $structs);
115
		} else {
116
			$params = array('inputStructArray' => array());
117
		}
118
	} else {
119
		$params = array('inputStructArray' => null);
120
	}
121
} elseif ($method == 'echoVoid') {
122
	$params = array();
123
} elseif ($method == 'echoBoolean') {
124
	if ($null != '1') {
125
		$params = array('inputBoolean' => false);
126
	} else {
127
		$params = array('inputBoolean' => null);
128
	}
129
} elseif ($method == 'echoBase64') {
130
	if ($null != '1') {
131
		$params = array('inputBase64' => base64_encode('You must encode the data you send; NuSOAP will automatically decode the data it receives'));
132
	} else {
133
		$params = array('inputBase64' => null);
134
	}
135
} else {
136
	echo 'Sorry, I do not know about method ' . $method;
137
	exit();
138
}
139
$client = new soapclient('http://www.scottnichol.com/samples/round2_base_server.php?wsdl&debug=1', true,
0 ignored issues
show
true of type true is incompatible with the type null|array expected by parameter $options of soapclient::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

139
$client = new soapclient('http://www.scottnichol.com/samples/round2_base_server.php?wsdl&debug=1', /** @scrutinizer ignore-type */ true,
Loading history...
140
						$proxyhost, $proxyport, $proxyusername, $proxypassword);
0 ignored issues
show
The call to soapclient::__construct() has too many arguments starting with $proxyhost. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

140
$client = /** @scrutinizer ignore-call */ new soapclient('http://www.scottnichol.com/samples/round2_base_server.php?wsdl&debug=1', true,

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
141
$err = $client->getError();
142
if ($err) {
143
	echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
144
}
145
$client->useHTTPPersistentConnection();
146
echo '<h2>Execute ' . $method . '</h2>';
147
$result = $client->call($method, $params);
148
// Check for a fault
149
if ($client->fault) {
0 ignored issues
show
The property fault does not seem to exist on SoapClient.
Loading history...
150
	echo '<h2>Fault</h2><pre>';
151
	print_r($result);
152
	echo '</pre>';
153
} else {
154
	// Check for errors
155
	$err = $client->getError();
156
	if ($err) {
157
		// Display the error
158
		echo '<h2>Error</h2><pre>' . $err . '</pre>';
159
	} else {
160
		// Display the result
161
		echo '<h2>Result</h2><pre>';
162
		print_r((!is_bool($result)) ? $result : ($result ? 'true' : 'false'));
163
		echo '</pre>';
164
		// And execute again to test persistent connection
165
		echo '<h2>Execute ' . $method . ' again to test persistent connection (see debug)</h2>';
166
		$client->debug("*** execute again to test persistent connection ***");
167
		$result = $client->call($method, $params);
168
		// And again...
169
		$client->debug("*** execute again ... ***");
170
		$result = $client->call($method, $params);
171
	}
172
}
173
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
0 ignored issues
show
The property request does not exist on SoapClient. Did you mean __last_request_headers?
Loading history...
174
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
0 ignored issues
show
The property response does not exist on SoapClient. Did you mean __last_response_headers?
Loading history...
175
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
0 ignored issues
show
The property debug_str does not seem to exist on SoapClient.
Loading history...
176
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
177