On 26/05/2021 17:20, Guilliam Xavier wrote:
I think you said the word: serialization. And especially*deserialization*,
e.g. from a JSON payload into a typed DTO*without*  calling the constructor
(then the DTO is passed through validation, which must handle uninitialized
typed properties "gracefully").


Would is_initialized() actually be all that useful there though?

- If you're iterating the properties dynamically, you'll probably be using the reflection API already - If you're listing them manually, you can validate the input rather than the output, which you'd have to do if there's any mapping of names or types anyway

It's also worth noting that If the property is not nullable, you can use isset() to tell if it's been initialised; and if it is nullable, you probably want it to default to null anyway.

A separate function is only needed if you've decided to use the uninitialised state as an extra "value", distinct from null.

Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to