Martin Scotta

On Wed, Feb 23, 2011 at 7:12 AM, Ben Schmidt
<mail_ben_schm...@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
>
>

Reply via email to