Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88316 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31732 invoked from network); 18 Sep 2015 10:11:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2015 10:11:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.177 mail-wi0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:38667] helo=mail-wi0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7B/37-19961-243EBF55 for ; Fri, 18 Sep 2015 06:11:15 -0400 Received: by wiclk2 with SMTP id lk2so24490051wic.1 for ; Fri, 18 Sep 2015 03:11:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=HWgXq/fg33K8vUxP3rqs4aP70QzUzbPu0fJgC+JUkcA=; b=K/0jSrJSZgihPbBR6hgs0pQBzi1rH+CpOY/4AGIgqmSZ5Le2uWG3yWkDwNhOPhzS8A +9yyRm2CqNGC01aCU5xFKSOAmqfa5o1UH+Jnxu6tD0G5Hn9YceVXPUXWgI4QOfy5Vff6 x7cO4+Lni493KWULFKyZ0/Uu3jDJW8yJfK51CQK2TN2e0KeiicjZAmgLyPIKytVXcKEn Djr3UOGoqA/Nl1aGgBNrYU9LVNuPGEG5KX/FvuSZJDgdEE/X+dkyrekUpBPXE5eaOHnc xKe0rbUK+07sw7CF43iUEPPJpkhpLoU77zBGkfxAg9LJBzpXdpGibeU7PeBBo684oZnc v2oA== X-Received: by 10.180.37.232 with SMTP id b8mr15723779wik.46.1442571071548; Fri, 18 Sep 2015 03:11:11 -0700 (PDT) Received: from [192.168.0.127] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id sd14sm8028711wjb.36.2015.09.18.03.11.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Sep 2015 03:11:11 -0700 (PDT) To: Jefferson Gonzalez , internals@lists.php.net References: <55FB4791.4040807@gmail.com> <55FB4DFC.2060204@domain.invalid> <55FB555C.9070701@gmail.com> <55FB7505.6000604@gmail.com> Message-ID: <55FBE306.3090204@gmail.com> Date: Fri, 18 Sep 2015 11:10:14 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55FB7505.6000604@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: Let's discuss enums! From: rowan.collins@gmail.com (Rowan Collins) Jefferson Gonzalez wrote on 18/09/2015 03:20: > 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";} > I would expect it to look more like this: e:16:"MembershipStatus":8:"INACTIVE" It seems to me that there are lots of things you could do to be efficient - declared object properties could be serialized by their ordinal position, rather than listing their names, for instance - but that would make the serialization more fragile. It seems to me that serializing enum values by order or "value" rather than name is much the same thing. > 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. Sure, but it seems more likely that somebody would add an extra value to an enum in alphabetical order, thus messing up serialized ordinals, than they are to refactor their code base to change the name of one of the values. And if you rename a class or property, serialized objects of that class will already break, so having serialized enums break on the same action seems perfectly natural, whereas having them silently unserialize to the wrong value because you changed the ordinal positions of the values seems rather dangerous. Regards, -- Rowan Collins [IMSoP]