-
Notifications
You must be signed in to change notification settings - Fork 7.8k
SoapClient can't convert BackedEnum to scalar value #15711
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
Comments
Somewhat related to #15650. Quoting from there:
So this is not a bug, but might be a legit feature request. |
cc @Crell and @iluuu1994 |
I think the main question here would be if we consider SOAPClient to be a serialization context. serialize(), json_encode(), etc. are, and so use the backing value. Would SOAPClient fall into that category? If so, pulling the backing value makes sense. If not, it doesn't. |
I think, we do. @nielsdos can possibly clarify. However, I'm not sure where to draw the line about what we support. https://pecl.php.net/package/xmlrpc is likely of no concern any longer, although XMLRPC can be regarded as precursor to SOAP. But there are likely more relevant packages, e.g. https://pecl.php.net/package/yaml. Well, not bundled extension probably need to decide for themselves, but what about XMLWriter and FFI (not really serialization, but somewhat related), for instance? |
What's the definition of "serialization context"? I guess it depends on that. |
Let me show you how I got to this issue. <xsd:simpleType name="AuthMethod">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="SessionToken"/>
<xsd:enumeration value="LoginProductAndPassword"/>
</xsd:restriction>
</xsd:simpleType> So I created Enum and DTO which I will pass to SoapClient enum AuthMethod: string
{
case SessionToken = 'SessionToken';
case LoginProductAndPassword = 'LoginProductAndPassword';
}
class AuthRequest
{
public function __construct(
public AuthMethod $AuthMethod,
public ?string $SessionToken = null,
public ?int $ProductId = null,
public ?string $Login = null,
public ?string $Password = null,
) {}
} For me it's seems reasonable, to expect for it to just work. If instead of SOAP it was some JSON RPC API I would just json_encode my DTO and it will work how I expected it. {
"AuthMethod": "SessionToken",
"SessionToken": "123345"
} |
Okay I see, it seems reasonable then to use the backing value. I'll take a look soon-ish. |
…ng response serialization
@nielsdos Works great! <xsd:simpleType name="TestIntegerEnum">
<xsd:restriction base="xsd:integer">
<xsd:enumeration value="1"/>
<xsd:enumeration value="2"/>
</xsd:restriction>
</xsd:simpleType> Which will result in error: Object of class TestIntegerEnum could not be converted to int |
Thanks for testing. Supporting this for ints makes sense, I'll give it a shot. |
…ng response serialization (string enums)
…ng response serialization (int enums)
@MrMeshok I updated the PR with support for int backed enums being serialized with xsd:integer (and alike) types. |
…ng response serialization (string enums)
…ng response serialization (int enums)
* PHP-8.3: Fix GH-15711: SoapClient can't convert BackedEnum to scalar value Use get_serialization_string_from_zval() in all encoding functions Introduce get_serialization_string_from_zval() and use it in to_xml_string()
Description
The following code:
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.3.11
Operating System
No response
The text was updated successfully, but these errors were encountered: