On Mon, Feb 14, 2011 at 12:45 PM, Thomas Gutbier <
thomas.gutb...@anthrotec.de> wrote:

> Jarrod Nettles wrote:
>
>> So, my proposed syntax would look something more like this.
>>
>
> I think also and was wondering about the current rfc for a few weeks.
> Im not a core developer but I want to outline what i would expect as
> php framework developer.
>
>
>  namespace System\Logs
>> {
>>                 enum Levels{
>>                                 DEBUG,
>>                                 INFO,
>>                                 WARNING,
>>                                 ERROR
>>                 };
>> }
>>
>
> Yes, after that I would expect a new type "Levels"
> and the possibility to do something like this:
>
> $log = new Levels;
> $log = WARNING;
> or
> $log = new Levels(WARNING);
>
> Like the current rfc i think, therefore we need the corresponding
> constants to be defined by defining the Levels type.
>
> Furthermore we should have the appropriate type hints for
> function/method calls.
>
> Assuming, we have a method like this
>
> public function setLogLevel (Levels $logLevel)
> {
>    $this->logLevel = $logLevel;
> }
>
> i would like to call them by delivering $log as a parameter
>
> $someLogginObject->setLogLevel($log)
>
> and get an error in the case the type of $log is not Levels.
>
> What do you think about a viable approach to
> implement a enum language structure.
>
> The current rfc seams not very useful for me.
>
> Thanks!
>
> Thomas Gutbier
> Web Developer
> Hannover, Germany
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
+1 with this!

but I don't understand is why the elements have to be scalar values.
If the "enum" is a class...

enum Token {

    IF ( array('if', T_IF)),
    FOR ( array('for', T_IF)),
    WHILE( array('while', T_IF)),
    PLUS ( '+' ),
    MINUS ( '-' );

    private $symbol;
    private $value;

    function __construct($token) {
        if (is_array($token)) {
            $this->value = $token[0];
            $this->symbol = $token[0];
            return
        }
        $this->value = $this->symbol = $token;
    }

    function getSymbol() { return $this->symbol; }
    function getValue() { return $this->value; }
}


function test(Token $t) {
    echo $t->getSymbol(), PHP_EOL, $t->getValue(), PHP_EOL;
}

test( Token::IF );
test( Token::PLUS );

Reply via email to