Re: [RFC] Enum proposal (yet another)

From: Date: Wed, 22 Feb 2012 06:02:16 +0000
Subject: Re: [RFC] Enum proposal (yet another)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-57932@lists.php.net to get a copy of this message
Right, but enums could possibly be a lot richer than class constants are now. They could be a type where the only values are what's defined in the enum. This could be used with type hinting: enum Foo { A, B, C } function bar(Foo $x) { // ... } There'd be no need to do any manual checking that $x is a valid value. Perhaps enum values could also be casted back to strings: (string)Foo::B; // "B" Sure, this is the kind of stuff that's possible in other ways already, but first class support always helps. On Feb 22, 2012 4:14 PM, "Laruence" <laruence@php.net> wrote: > On Wed, Feb 22, 2012 at 12:45 PM, Samuel Deal <samuel.deal@gmail.com> > wrote: > > Hi all, > > > > I really missed enums in PHP, > Why? we have class constant. > > thanks > > So after reading I tryed to synthetise the various views. > > > > You can find a draft here : > > https://github.com/SamNrique/php-src/wiki/RFC-draft > > (I can't write on the wiki, and perhaps it's better to finish the > > discussion first) > > > > There's an implementation with this draft. > > I'd love to have feedbacks because it's my first php-core hack. > > > > Thanks > > -- > > Samuel Déal > > samuel.deal@gmail.com > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.internals (#57932) next »