Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot assign array to property #289

Open
mwolff-fn opened this issue Mar 3, 2023 · 5 comments
Open

TypeError: Cannot assign array to property #289

mwolff-fn opened this issue Mar 3, 2023 · 5 comments
Assignees
Labels

Comments

@mwolff-fn
Copy link

Prerequisites

We have a SOAP method getProduct() where the response contains property "externalAttributes", which is defined as a Map struct in the WSDL:
<element name="externalAttributes" nillable="true" type="apachesoap:Map"/>

In the generated proxy class for the response, I see the property generated with the appropriate typehint:

/**
 * The externalAttributes
 * Meta information extracted from the WSDL
 * - nillable: true
 * @var \My\Namespace\Struct\Map|null
 */
protected ?\My\Namespace\Struct\Map $externalAttributes = null;

The Map struct class is properly generated and extends WsdlToPhp\PackageBase\AbstractStructBase.

Error message

Now, when I call the method doing the actual SOAP call, I'm getting this exception:

TypeError Cannot assign array to property My\Namespace\Struct\ProductAttribute::$externalAttributes of type ?My\Namespace\Struct\Map

SOAP response

In the raw SOAP response, I see the data represented like this:

<externalAttributes href="#id55"/>
...a gazillion nodes later...
<multiRef xmlns:ns31="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" id="id55" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns31:Map">\n
  <item>\n
    <key xsi:type="soapenc:string">LNG</key>\n
    <value href="#id97"/>\n
  </item>\n
  <item>\n
    <key xsi:type="soapenc:string">CDB</key>\n
    <value href="#id98"/>\n
  </item>\n
</multiRef>

Expectation

I would have expected the data to be parsed into the Map class.

What actually happens

While trying to interpret the response and hydrating the proxy class, the client seems to fail identifying the Map struct as such and simply converts the data into an associative array.

When I remove the type hints from the response struct class, the error message goes away and I can see the parsed data structure, which looks like this:

"externalAttributes": [
        "LNG" => SoapVar {#2857
          +enc_type: 0
          +enc_value: My\Namespace\Struct\ExternalAttribute^ {#2856
            #ID: 44
            #attributeId: 103
            #attributeName: "realaccount"
            #attributeType: "String"
            #productAttribute: My\Namespace\Struct\ProductAttribute^ {#2855}
            #systemId: "LNG"
          }
          +enc_stype: "ExternalAttribute"
          +enc_ns: "//productcatalog/beans"
          +enc_name: null
          +enc_namens: null
        }
        "CDB" => SoapVar {#2859
          +enc_type: 0
          +enc_value: My\Namespace\Struct\ExternalAttribute^ {#2858
            #ID: 517
            #attributeId: 103
            #attributeName: "realaccount"
            #attributeType: "String"
            #productAttribute: My\Namespace\Struct\ProductAttribute^ {#2855}
            #systemId: "CDB"
          }
          +enc_stype: "ExternalAttribute"
          +enc_ns: "//productcatalog/beans"
          +enc_name: null
          +enc_namens: null
        }
      ]

I am currently using PHP8.1, wsdltophp/packagebase:5.0.3 and PackageGenerator 4.1.7.

Is there a possible workaround other than to deactivate strict typing?

@mikaelcom
Copy link
Member

Intriguing!

Can you provide the Map class declaration? From my point of view, the Map should contain an array-typed property or something like this.

Let me know, feel free, if possible, to send me the WSDL at [email protected]

@mikaelcom mikaelcom self-assigned this Mar 4, 2023
@mwolff-fn
Copy link
Author

Thanks for the quick reply - sent you the files earlier today.

@mikaelcom mikaelcom added the bug label Apr 1, 2023
@mikaelcom mikaelcom transferred this issue from WsdlToPhp/PackageBase Apr 1, 2023
@mikaelcom
Copy link
Member

From my point of view, the generated classes match the WSDL definition.

I'm wondering if the SOAP response is well defined and if it does match the WSDL definition.

Maybe if I was able to send the request by myself, maybe I would be able to understand where the issue comes from and if it can be worked around.

Let me know then.

@mwolff-fn
Copy link
Author

Thanks for looking into it. Unfortunately, the service is within a private network, so you can't access it from the outside. But if it helps, I could probably provide you with a complete protocol of a request/response cycle in private.

@mikaelcom
Copy link
Member

Thanks for looking into it. Unfortunately, the service is within a private network, so you can't access it from the outside. But if it helps, I could probably provide you with a complete protocol of a request/response cycle in private.

If you can provide the full XML response, I could work with it I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants