Re: Re: Clarification on the Enum language structure

From: Date: Sat, 19 Feb 2011 05:03:06 +0000
Subject: Re: Re: Clarification on the Enum language structure
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-51471@lists.php.net to get a copy of this message
On 2/18/2011 9:28 PM, Ben Schmidt wrote:
I did some research on methods in enums and discovered that there is some usefulness to the idea - I wouldn't go so far as to say that they would be needed, but C#, for example, allows you to create extension methods for enums and MSDN has a decent real-world example of its use. http://msdn.microsoft.com/en-us/library/bb383974.aspx
It's a pretty big new concept that would need to be introduced if this was desired: extension methods. I think it's overkill myself. Something like this is fine: class Grade { enum { A_PLUS, A, B_PLUS, B, ..., FAIL, NOT_AVAILABLE, } public static function passing($grade) { return $grade>=self::D; } } $grade=Grade::B; echo Grade::passing($grade)?"passing":"not passing";
Shouldn't that be: public static function passing($grade) { -return $grade>=self::D; +return $grade<=self::D; The passing grades all appear before D in the enum, and I expect those to have lower values. Also, I would probably put NOT_AVAILABLE first, since it's underlying value is 0. But then the programmer isn't supposed to consider the underlying values... Rick

« previous php.internals (#51471) next »