Re: Bitwise Declaration of Flags

From: Date: Sun, 27 Sep 2009 14:40:42 +0000
Subject: Re: Bitwise Declaration of Flags
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-45641@lists.php.net to get a copy of this message
On Sun, 27 Sep 2009, jvlad wrote: > > This is not allowed since declaration values should be resolvable at > > compile time. I.e. they can not be an expression, but only a value > > literal. > > > > While technically expression folding is possible, it's not > > implemented in any part of the PHP engine (AFAIK), and I don't think > > it's planned any time soon. > > > > To do what you want, initialize the value in the constructor: > > > > class foo { > > ... > > private $flags; > > > > function __construct() > > { > > $this->flags = self::FLAG_1 | self::FLAG_3; > > } > > } > > > > ok, and could you please point out to the thing in self::FLAG_1 that > is unresolveable at compile-time? The following is also valid syntax: class foo { private $Flags = self::FLAG_1 | self::FLAG_3 const FLAG_1 = 1; const FLAG_2 = 2; const FLAG_3 = 4; } When the compiler hits self::FLAG_1 here, it's not yet defined. Derick -- http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org twitter: @derickr

« previous php.internals (#45641) next »