php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46427 SoapClient() stumbles over its "stream_context" parameter
Submitted: 2008-10-30 11:05 UTC Modified: 2008-11-27 11:29 UTC
From: daniel dot gorski at develnet dot org Assigned: dmitry (profile)
Status: Closed Package: SOAP related
PHP Version: 5.3.0alpha2 OS: Linux
Private report: No CVE-ID: None
 [2008-10-30 11:05 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-25 02:06 UTC] 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-11-27 11:29 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC