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

Invalid doc blocks regarding serialization #159

Open
javaDeveloperKid opened this issue Mar 31, 2024 · 1 comment
Open

Invalid doc blocks regarding serialization #159

javaDeveloperKid opened this issue Mar 31, 2024 · 1 comment
Labels
doc Documentation

Comments

@javaDeveloperKid
Copy link

javaDeveloperKid commented Mar 31, 2024

Detailed description:

The methods in Enum class related to serialization have the following sentence in the doc block: Enums are not serializable because instances are implemented as singletons.
When I first heard of enums and started using them with the help of this library and read I this sentence, I thought this describes the nature of enums, i.e. enum as a data type is unserializable by definition. However after some time, when I gained more programming knowledge I know that enums are serializable even though they are singletons but this cannot be implemented in pseudo-enum implementation via PHP classes.

Expected behavior:
Change the doc block to something like "Serialization is not supported as in this pseudo-enum implementation there is no way to unserialize and keep the enum cases as singletons at the same time." (feel free to reword).

@marc-mabe
Copy link
Owner

Hi @javaDeveloperKid,

Thanks for your report.

The doc-block comment refers to the class Enum of this library and not to enums in general.
I agree with you that this might not to be very clear.

Also note, this is true only for this Enum class where on the other side this library also provides a way to support serializing Enum instances in a limited way see https://github.com/marc-mabe/php-enum/tree/master?tab=readme-ov-file#serializing (that's why it must be done manually).

A PR would be welcome to clarify the doc block.

PS: Since PHP 8.1 enums are natively supported! As long as a EnumSet / EnumMap is not needed and no older PHP version targeted, I would highly recommend using native enums: https://www.php.net/manual/language.types.enumerations.php

@marc-mabe marc-mabe added doc Documentation and removed bug labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Documentation
Projects
None yet
Development

No branches or pull requests

2 participants