Re: Re: Clarification on the Enum language structure
| From: | Martin Scotta | Date: | Wed, 23 Feb 2011 13:35:16 +0000 |
| Subject: | Re: Re: Clarification on the Enum language structure | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51513@lists.php.net to get a copy of this message | ||
Martin Scotta
On Wed, Feb 23, 2011 at 7:12 AM, Ben Schmidt
<mail_ben_schmidt@yahoo.com.au>wrote:
> Are you suggesting this as an enum member function, or just a regular
>>> function in any old class?
>>>
>>
>> "Enum member funcion"? How much it should be like a class before you
>> call it a class?
>>
>
> Exactly. It's crazy. If you want a 'member function' use a class, not an
> enum.
>
why not supporting methods for enum values?
developers will need that, and by providing type hinting, they will just
create the logic somewhere else...
enum MyEnum {
/// enum entries here
}
class MyEnumLogic {
private $e;
function __construct(MyEnum $e) { $this->e = $e; }
function doSomething() {
/// do something with $this->e
}
}
// or..
function MyEnum_doSomething(MyEnum $e) {
/// do something with $e
}
too much boilerplate for just a simple...
enum MyEnum {
/// enum entries here
function doSomething() {
/// do something with $this
}
}
and what about client code?
function client_version_1(MyEnum $e) {// we got MyEnum
$e = new MyEnumLogic($e); // but we need to wrap it... every call
return $e->doSomething($e);
}
function client_version_2(MyEnum $e) {
return MyEnum_doSomething($e);// the func version is cheaper than ver 1
}
function client_version_2(MyEnum $e) {
return $e->doSomething();// so what wrong with this?
}
>
> use the function: you would usually be expected to pass in a true enum
>>> constant of the MyEnum type.
>>>
>>
>> That works wonders in dynamic languages, without any means of really
>> ensuring it.
>>
>
> No, I believe you can ensure it, and you can even ensure it efficiently.
> I outlined this in a more lengthy email earlier today. I was against
> type hinting until I realised that yes, it could work, and work
> efficiently.
>
> Ben.
>
>
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>