PHP 7.1.0 Release Candidate 4 Released

The SoapHeader class

(PHP 5 >= 5.0.1, PHP 7)


Represents a SOAP header.


SoapHeader {
/* Methoden */
SoapHeader ( string $namespace , string $name [, mixed $data [, bool $mustunderstand = false [, string $actor ]]] )


add a note add a note

User Contributed Notes 3 notes

voroks at logics dot net dot au
1 year ago
Example by john at jtresponse dot co dot uk does miss one important point: to be able to add attributes they must be mentioned in WSDL. If they not exist in WSDL they WILL NOT appear as attributes but rather <item><key/><value/></item> elements.
john at jtresponse dot co dot uk
4 years ago
None of the examples really do it for me.
Note: you should NOT need to hard-code any XML.

Here is an example of creating a nested header and including a parameter.

$client = new SoapClient(WSDL,array());

$auth = array(
        'SystemId'=> array('_'=>'DATA','Param'=>'PARAM'),
  $header = new SoapHeader('NAMESPACE','Auth',$auth,false);

Gives the following header XML:

      <ns1:SystemId Param="PARAM">DATA</ns1:SystemId>
abdul dot rashid at paytabs dot co
7 months ago
Just to add some note regarding his john at jtresponse dot co dot uk

In PHP you can try following code to avoid the <item><key/>

$Auth = new stdClass();
$Auth->SystemId = "DATA";
$Auth->UserName = "USERNAME";
$Auth->Password = "PASSWORD";

$header = new SoapHeader('NAMESPACE','Auth',$Auth,false);

To Top