ID:               46427
 Updated by:       [EMAIL PROTECTED]
 Reported By:      daniel dot gorski at develnet dot org
-Status:           Open
+Status:           Verified
 Bug Type:         SOAP related
 Operating System: Linux
 PHP Version:      5.3.0alpha2
 New Comment:

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());


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to