2017-02-15 21:25 GMT+01:00 Michał Brzuchalski <mic...@brzuchalski.com>:
> Assumming they would be closer to immutable objects they may have some > usefull... I was gonna say methods but the term doesn't fit to enums. > But using one of my favourite userland implementation such as `esky\enum` > package there are ways to create enumeration from value or from name. > Those methods are quite usefull when converting user data passed in > request from string to enumeration. > Given the example: > > enum Day { > MONDAY, > TUESDAY, > WEDNESDAY, > THURSDAY, > FRIDAY, > SATURDAY, > SUNDAY > } > > When using passed from request data proper enumeration could be restored > for eg. > > $_GET['day'] = 'MONDAY'; > $day = Day::fromName($_GET['day']); // Day.MONDAY > > or by value > > $day = Day::fromValue(0); // Day.MONDAY > > Think of it as possible way of restoring from primitive types because then > enums would really be closer to classes than values. > And also then could even utilise `object > typehint so it'll accept enums also. (Sorry for second mail - unintended Ctrl+Enter) > > 2017-02-15 20:53 GMT+01:00 Rasmus Schultz <ras...@mindplay.dk>: > >> In the light of this, maybe enums (assuming this feature comes first) >> should be implemented as immutable objects rather than values? >> >> Type-checking for enums would be important, so in PHP terms, an enum >> "instance" would likely be closer to an object than a value in nature >> anyway. >> >> The way I look at it, this feature doesn't prevent enums from happening, >> it >> just changes the design parameters. >> >> Just a thought. >> >> >> On Wed, Feb 15, 2017 at 4:34 PM, Andrea Faulds <a...@ajf.me> wrote: >> >> > Hi Marco, >> > >> > Marco Pivetta wrote: >> > >> >> >> >> Since the engine is clueless about types until autoloading happens, >> this >> >> is >> >> easily solvable by providing a marker syntax for non-object hints. For >> >> instance `function foo() : enym:MyEnum {}` >> >> >> > >> > If we're going to do prefixes for non-classes, we might as well copy C >> > outright: `enum MyEnum`. >> > >> > Thanks. >> > -- >> > Andrea Faulds >> > https://ajf.me/ >> > >> > >> > -- >> > PHP Internals - PHP Runtime Development Mailing List >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> > > > > -- > regards / pozdrawiam, > -- > Michał Brzuchalski > about.me/brzuchal > brzuchalski.com > -- regards / pozdrawiam, -- Michał Brzuchalski about.me/brzuchal brzuchalski.com