Am 22.02.2012 22:30, schrieb Sebastian Krebs:
> Am 22.02.2012 22:22, schrieb Ángel González:
>> I want to call it doSomething(FOO) or doSomething(MyEnum::FOO),
>> not doSomething(new MyEnum(MyEnum::FOO));
>
>
> // The class file
> class MyEnum {
>      public static $FOO;
>      public static $BAR;
>      const FOO = 'foo';
>      const BAR = 'bar';
>      private $value;
>      public function __construct ($value) {
>          if (!in_array($value, array(self::FOO, self::BAR)) throw new
> UnexpectedValueException;
>          $this->value = $value;
>      }
>      public function __toString () { return $this->value; }
> }
> /* static code block */ {
>   // As long as PHP doesn't support "constant references" (;))
>   // (--> constants with objects or arrays)
>   MyEnum::$FOO = new MyEnum(MyEnum::FOO);
>   MyEnum::$BAR = new MyEnum(MyEnum::BAR);
> }
> // End class file
This gets even much more ugly.
Your workaround could have been acceptable if PHP autoconverted into a
class, though (á la C++).

> // Somewhere deep within some other code
> doSomething (MyEnum::$FOO);
>
>
> However, I can't see, what is the big thing, that isn't currently not
> possible (except any "I want"-argumentation :X)
If we are going to have only features which aren't possible in other
ways, then we can begin by removing loops, as
you can replace them with if + goto.
Some parser features are important because they allow to implement
things that wouldn't otherwise be possible. Others, just provide a way
to do things which would have "only" been very complex.

> Sidenote, according your examples above on how you want call
> functions: Considered using normal constants?
How can I do type hinting with them?



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

Reply via email to