PHP 8.6.0 Beta 1 is available for testing

SoapClient::__getTypes

(PHP 5, PHP 7, PHP 8)

SoapClient::__getTypesReturns a list of SOAP types

Description

public function SoapClient::__getTypes(): ? array

Returns an array of types described in the WSDL for the Web service.

Note: This function only works in WSDL mode.

Parameters

This function has no parameters.

Return Values

The array of SOAP types, detailing all structures and types.

Examples

Example #1 SoapClient::__getTypes() example

<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getTypes());
?>

The above example will output:

array(88) {
 [0]=>
 string(30) "ProductLine ProductLineArray[]"
 [1]=>
 string(85) "struct ProductLine {
 string Mode;
 string RelevanceRank;
 ProductInfo ProductInfo;
}"
 [2]=>
 string(105) "struct ProductInfo {
 string TotalResults;
 string TotalPages;
 string ListName;
 DetailsArray Details;
}"
...
 [85]=>
 string(32) "ShortSummary ShortSummaryArray[]"
 [86]=>
 string(121) "struct GetTransactionDetailsRequest {
 string tag;
 string devtag;
 string key;
 OrderIdArray OrderIds;
 string locale;
}"
 [87]=>
 string(75) "struct GetTransactionDetailsResponse {
 ShortSummaryArray ShortSummaries;
}"
}

See Also

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 2 notes

up
22
felipe dot cwb at hotmail dot com
12 years ago
<?php
// to see formated types
$soap = new SoapClient('http://domain.com/ws.php?WSDL');
echo '<pre>';
echo '<h2>Types:</h2>';
$types = $soap->__getTypes();
foreach ($types as $type) {
 $type = preg_replace(
 array('/(\w+) ([a-zA-Z0-9]+)/', '/\n /'),
 array('<font color="green">${1}</font> <font color="blue">${2}</font>', "\n\t"),
 $type
 );
 echo $type;
 echo "\n\n";
}
echo '</pre>';
up
1
Serge Liatko
3 years ago
Here is the fixed version of my previous code (@moderators , please delete my previous note )
Returns a more comprehensive array of SOAP Client types as an array
<?PHP
/**
 * @param \SoapClient $soap
 *
 * @return array The WSDL types data as an array.
 */
function read_wsdl_types( SoapClient $soap ): array {
 $wsdl_types = $soap->__getTypes();
 $lookup = array();
 $regexes = array(
 'atomic' => '/^([\w_]+)\s([\w_]+)$/mi',
 'list' => '/^([\w_]+)\s([\w_]+)[ {]+([\w_]+)[ }]+$/mi',
 'struct' => '/([\w_]+)\s([\w_]+)[\s{]?([\w_]+)*[\s;}]?/mi',
 );
 foreach ( array_reverse( $wsdl_types ) as $wsdl_type ) {
 $matches = array();
 foreach ( $regexes as $type => $regex ) {
 if ( preg_match_all( $regex, $wsdl_type, $matches ) ) {
 break;
 }
 }
 if ( !empty( $matches[1] ) && !empty( $matches[2] ) ) {
 switch ( $type ) {
 case 'atomic':
 $name = array_shift( $matches[2] );
 $data_type = array_shift( $matches[1] );
 $lookup[ $name ] = array(
 'name' => $name,
 'type' => $type,
 'data_type' => $data_type,
 'items' => array(),
 );
 break;
 case 'list':
 $name = array_shift( $matches[2] );
 $type = array_shift( $matches[1] );
 $items = array_shift( $matches[3] );
 $lookup[ $name ] = array(
 'name' => $name,
 'type' => $type,
 'data_type' => $items,
 'items' => array(
 array(
 'name' => '',
 'data_type' => $items,
 ),
 ),
 );
 break;
 case 'struct':
 $name = array_shift( $matches[2] );
 $type = array_shift( $matches[1] );
 $items = array();
 foreach ( $matches[2] as $key => $item_name ) {
 $items[ $key ] = array(
 'name' => $item_name,
 'data_type' => $matches[1][ $key ],
 );
 }
 $lookup[ $name ] = array(
 'name' => $name,
 'type' => $type,
 'data_type' => $name,
 'items' => $items,
 );
 break;
 }
 }
 }
 array_walk( $lookup, function ( &$type, $key, $data ) {
 if ( !empty( $type['items'] ) ) {
 array_walk( $type['items'], function ( &$item, $key, $data ) {
 if ( !empty( $item['data_type'] ) ) {
 $old_data_type = $item['data_type'];
 $item['type'] = $data[ $old_data_type ]['type'] ?? 'atomic';
 $item['data_type'] = $data[ $old_data_type ]['data_type'] ?? $old_data_type;
 $item['from'] = $data[ $old_data_type ]['name'] ?? '';
 }
 }, $data );
 }
 }, $lookup );
 return array_reverse( $lookup );
}
?>
+add a note

AltStyle によって変換されたページ (->オリジナル) /