Re: Re: Clarification on the Enum language structure

From: Date: Thu, 17 Feb 2011 19:56:55 +0000
Subject: Re: Re: Clarification on the Enum language structure
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-51461@lists.php.net to get a copy of this message
On 17 February 2011 19:32, Martin Scotta <martinscotta@gmail.com> wrote: > On Thu, Feb 17, 2011 at 3:01 PM, Jarrod Nettles <JNettles@inccrra.org>wrote: > >> An enum is not a class. > > totally agree. an enum is a family of related constant values. > > >> It has no methods or properties and is not something that you instantiate. >> > partially agree, you cannot instantiate nor destruct a constant. > it's a value that does not change over time, but why can't it be an > immutable object? > > >> >> Also, I feel like it should be restricted to integral types only, and >> defaults to a zero-based incrementing integer. This is more in line with >> other programming languages that already implement enums and will present >> "expected behavior" for people moving over to PHP. >> > for me that's a plain old interpretation of constants. > constant values were only integer values because of their implementation, > nowadays they could be anything you want, int, float, string and even > objects. > > enum MyEnum { >      A, B, C; >      function test() { return true; } > } > > $value = MyEnum:B; > > if ( $value->test() ) { >    echo ' what is wrong with this ? '; > } That looks like a mix of an enum and a struct. Can you provide any realworld examples where an enum contains anything other than integers? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

« previous php.internals (#51461) next »