On 09/17/2015 08:05 PM, Rowan Collins wrote:
I don't think serializing to a name is particularly more inefficient
than serializing to an integer - depending on the internal
implementation, of course. Or do you mean efficiency in terms of the
length of the string produced?

Exactly! Lets say you want to create a MembershipStatus

enum MembershipStatus{
    INACTIVE=0,
    ACTIVE=1
}

It would be more memory/space efficient to store 1 or 0 in a database or serialized string, also it would be faster to parse than storing the full name, eg (bad serialized example but just to show the idea):

e:16:"MembershipStatus":1:{i:0;}

instead of

e:16:"MembershipStatus":1:{s:8:"INACTIVE";}

Nor do I see it as particularly likely that somebody will rename an enum
member - that would instantly break all code referring to it anyway.
They could however change the order of fields without realising that it
would make any difference, since most access would be of the form
TypeName::ValueName.

Regards,


The renaming thingy, I'm wouldn't be so sure because IDE's can introduce refactoring tools for enumerations that rename all occurrences of an enum to another. Unless you are working on a public framework that many different people is using, in that case you would restraint from renaming the enumerations.


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

Reply via email to