Re: Re: Let's discuss enums!
| From: | Dan Cryer | Date: | Tue, 22 Sep 2015 15:06:48 +0000 |
| Subject: | Re: Re: Let's discuss enums! | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88407@lists.php.net to get a copy of this message | ||
>
> You can always serialize things however you want. Using
>
serialize()
> is just a convenience – there is absolutely nothing that prevents you
> from using a custom serialization routine. Note that while Java has
> built in serialization it is often not used, and instead libraries
> like Google's GSON are used. You register a type with hooks for
> serializing and deserializing, etc.
>
> It sounds like this is what you need anyway. Since built-in
> serialization happens differently in each language you'd probably want
> something custom in each language.
>
Whilst that might be the case with *serialize()*, by extension you also
lose the convenience of being able to use *json_encode() *on an already
properly structured object and immediately having a representation of that
object ready to send over the wire.
C#'s enums seem a good model to follow. 0-indexed by default, alternatively
you can specify the first key to change to (for example) 1-indexed or
specify all keys:
enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};