Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51448 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62526 invoked from network); 14 Feb 2011 17:27:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Feb 2011 17:27:31 -0000 Authentication-Results: pb1.pair.com header.from=martinscotta@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=martinscotta@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: martinscotta@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:53365] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/03-44718-206695D4 for ; Mon, 14 Feb 2011 12:27:30 -0500 Received: by vxc38 with SMTP id 38so2783156vxc.29 for ; Mon, 14 Feb 2011 09:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=RYoY67YQtPVzsRmJe6PB77ispNUz+9fo/Re3ozrlSpo=; b=El0bHbzG+F6R6+y4TpieKZL6qjZlzYb6yzoRRB6dV/zieIF9GF2xXNabf/wqN65svD kf6TC4CI8sUMKxK2Xsq25vJbd99DTKQFYSfpWUVkpePTKTaa2C/eBpzvJg5sHR7eCpgX LPu68FBZvXo0lvZ94cl+5lYD8W1sH6aLucFHE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=rDrnVT0WEMWoHbLGnPVdepAsXiScSs77mniNztt6JvCOo3giqwZlk0zx8inPQhdWF5 /pTtEyRIyP2A3uNplAuoQeseDINUXaLDfRyAXj0SkwxryFaseEF66DZvpT6KP54siA7J qFdjVnOT9Pep6bpFddRFBfsScBshSHq0wLR8k= MIME-Version: 1.0 Received: by 10.220.201.194 with SMTP id fb2mr1304860vcb.199.1297704446721; Mon, 14 Feb 2011 09:27:26 -0800 (PST) Received: by 10.220.183.77 with HTTP; Mon, 14 Feb 2011 09:27:26 -0800 (PST) In-Reply-To: References: <8423995CEEEA844CB2F964B14BCA94CD043A9686@PRODEXCHANGE02.ilchildcare.org> Date: Mon, 14 Feb 2011 14:27:26 -0300 Message-ID: To: Thomas Gutbier Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=90e6ba48835992156d049c415ccf Subject: Re: [PHP-DEV] Re: Clarification on the Enum language structure From: martinscotta@gmail.com (Martin Scotta) --90e6ba48835992156d049c415ccf Content-Type: text/plain; charset=ISO-8859-1 On Mon, Feb 14, 2011 at 12:45 PM, Thomas Gutbier < thomas.gutbier@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 ); --90e6ba48835992156d049c415ccf--