public function Killjoy(MyEnum $x)

What would be the purpose of such code? What would it do if 5 is passed as
$x?

Are you suggesting this as an enum member function, or just a regular
function in any old class?

If 'in an enum', I think by analogy with the stuff somebody linked to on
the MS site to do with C#, it can only ever be invoked by doing
EnumConstant.Killjoy(); and EnumConstant is automatically passed as an
argument to the function--you could never pass 5. I think this is a bit
crazy, though, blurring the lines between enums and classes way too
much, and not a good idea for PHP.

If just 'any old function', there are two possibilities: if 5 is passed,
the type hint recognises that 5 is not of the MyEnum type, so fails; you
would have to explicitly cast 5 as a MyEnum when calling the function to
make it work; or the other possibility is that Killjoy attempts a cast
and only fails if 5 cannot be cast to the enum (I prefer this way). In
both cases, though, that would not be expected to be the usual way to
use the function: you would usually be expected to pass in a true enum
constant of the MyEnum type.

Ben.




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to