How to make a PHP SOAP call using the SoapClient class

How to make a PHP SOAP call using the SoapClient class

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding PHP SOAP Calls When Type Names Mismatch Variable Keys

Interacting with a SOAP service often feels like playing a guessing game if you rely solely on the raw output of __getTypes() and __getFunctions(). The standard approach suggested by many online examples assumes a flat associative array maps directly to function parameters. However, when the WSDL defines specific complex types—like a struct named Contact—and your local variable keys like id, name, or description do not match that type's definition exactly, the SoapClient throws an error stating "Object has no 'Contact' property."

This error occurs because the client library expects you to instantiate the specific complex types defined in the schema before passing them to the function. If your WSDL defines a parameter as struct Contact { id; name; }, simply passing an array with keys id and name is insufficient. The SOAP envelope must know that these keys belong to a Contact object, not just loose fields.

To resolve this, you must inspect the actual function signature returned by __getFunctions(). In your specific case, the output shows:
"FirstFunction Function1(FirstFunction $parameters)"

This indicates two critical things. First, the parameter type for the function is explicitly named FirstFunction, not Contact. Second, the structure of the arguments passed to that function depends entirely on what $parameters expects inside the WSDL schema. If the WSDL defines FirstFunction as taking a single complex object of type Contact, plus two separate primitive strings and an integer, your PHP array must reflect that hierarchy.

The most reliable way to construct the payload is to ensure your associative arrays mirror the exact structure expected by the WSDL types. Based on the __getTypes() output showing struct Contact containing id and name, and assuming the function signature implies a single Contact object followed by description and amount, the correct syntax requires nesting the data into an array that matches the function's argument list order.

However, there is often a discrepancy between the variable keys in your code and the type names in the WSDL. If your WSDL defines the struct as struct Contact, but the function signature expects a parameter named FirstFunction, passing a simple array like ["id" => 100, "name" => "John"] will fail because the server cannot map those loose keys to the expected complex type without an explicit wrapper.

The solution usually involves wrapping your data in an array that corresponds to the function's argument list. If the WSDL defines a function FirstFunction(Contact $contact, string $description, int $amount), your PHP call must look like this:

$client = new SoapClient("http://example.com/webservices?wsdl");

// Construct the payload matching the function signature order
$params = [
    'Contact' => [
        'id' => 100,
        'name' => 'John',
    ],
    'description' => 'Barrel of Oil',
    'amount' => 500,
];

$response = $client->__soapCall('Function1', $params);

In this example, the key 'Contact' acts as the type name that bridges your PHP array to the WSDL definition. The server then reads the nested id and name as properties of that Contact struct. If your WSDL uses a different naming convention for the complex type within the function arguments, you must adjust the wrapper key accordingly.

A common pitfall is assuming that __getTypes() output is the full story. The var_dump shows available structs and strings, but it does not explicitly map which struct belongs to which parameter in a specific function call. You often need to infer this from the function signature string or consult the WSDL directly. If the FirstFunction signature implies a single composite argument rather than three separate ones, your PHP array structure must change to reflect that nesting, even if the underlying data remains the same.

Another potential issue arises when the SOAP client attempts to serialize your data but cannot find a matching type definition for the wrapper key you provided. If the WSDL defines the complex type as Contact but your code passes an array keyed by FirstFunction, the serialization will fail because the server expects properties belonging to Contact, not FirstFunction. Always verify that the wrapper keys in your PHP array match the exact type names defined in the WSDL's complexType sections.

By aligning your PHP arrays with the specific struct names and argument orders defined in the WSDL, you eliminate the "Object has no 'X' property" errors. The key is treating the SOAP client not as a generic function caller, but as a strict serializer that demands the exact schema structure you provide.

Our network