#46427 [Ver->Asn]: SoapClient() stumbles over its "stream_context" parameter
| From: | dmitry@php.net | Date: | Tue, 25 Nov 2008 08:53:48 +0000 |
| Subject: | #46427 [Ver->Asn]: SoapClient() stumbles over its "stream_context" parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-131293@lists.php.net to get a copy of this message | ||
ID: 46427
Updated by: dmitry@php.net
Reported By: daniel dot gorski at develnet dot org
-Status: Verified
+Status: Assigned
Bug Type: SOAP related
Operating System: Linux
PHP Version: 5.3.0alpha2
-Assigned To:
+Assigned To: dmitry
Previous Comments:
------------------------------------------------------------------------
[2008-11-25 02:06:56] hradtke@php.net
In example 1, the $ctx variable is declared within the scope of the
getSoapClient_1() function. The SoapClient constructor does not make a
copy of the stream context. That stream context resource is destroyed
when the function returns.
Patch that copies the stream context if someone wants to review and
commit:
http://www.hermanradtke.com/soap_client_stream_context.patch
Since you are using PHP 5.3 you can use a closure. The syntax is a
little different than something like JavaScript. Try the following in
the meantime:
function getSoapClient_1() {
$ctx = stream_context_create();
return function() use ($ctx) {
return new SoapClient(URI, array('stream_context' => $ctx));
};
}
$client = getSoapClient_1();
$client()->__soapCall('Help', array());
------------------------------------------------------------------------
[2008-10-30 11:05:16] daniel dot gorski at develnet dot org
Description:
------------
SoapClient()'s "stream_context" parameter gets mangled if used in a
function. The stream context becomes disfunctional.
Below are two examples listed of which one does not work. Although not
quite sure, this might be also related to #46096.
Reproduce code:
---------------
error_reporting(E_ALL|E_STRICT);
define(
'URI',
'http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl'
);
// Example 1, emits a warning, mangles value of $ctx.
function getSoapClient_1() {
$ctx = stream_context_create();
return new SoapClient(URI, array('stream_context' => $ctx));
}
// Explicit output not required to see the error/warning.
getSoapClient_1()->__soapCall('Help', array());
// ---
// Example 2, works as far I can see.
$ctx = stream_context_create();
function getSoapClient_2($ctx) {
return new SoapClient(URI, array('stream_context' => $ctx));
}
// No output, no warning, seems OK.
getSoapClient_2($ctx)->__soapCall('Help', array());
Expected result:
----------------
At least no output as not output is triggered.
Actual result:
--------------
"Warning: SoapClient::__doRequest(): XX is not a valid Stream-Context
resource in [...]"
Where the XX is the resource number id. Interestingly the output is not
"Resource #XX .." but just the number "XX" without the leading hash.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46427&edit=1