Re: [RFC] Constant Scalar Expressions

From: Date: Wed, 14 Aug 2013 10:52:12 +0000
Subject: Re: [RFC] Constant Scalar Expressions
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-68511@lists.php.net to get a copy of this message
On Wed, Aug 14, 2013 at 12:44 PM, Anthony Ferrara <ircmaxell@gmail.com>wrote: > Stas, > > > On Wed, Aug 14, 2013 at 5:01 AM, Stas Malyshev <smalyshev@sugarcrm.com>wrote: > >> Hi! >> >> >> https://wiki.php.net/rfc/const_scalar_expressions >> >> I like the idea, but absence of constant support makes this thing much >> less useful, as you can't do things like: >> >> public $angle = M_PI/2; >> >> I think this is one of the reasons this idea was never implemented - >> because without constant support you're limited to doing things that are >> quite obvious and trivial. >> > > Yeah, having constants in those expressions would be great. If only > constants in PHP were actually constant... > > But this win is really cheap (a trivial change to the parser), so I > figured it was worth proposing separately. If we want to add the opcode > stream later to do expressions for constant values, we can. This just gives > us the quick win today of allowing relatively trivial, but important > expressions. > > The biggest wins I see are in power-of-2 math: > I agree ! > > class Foo { > const FLAG_1 = 1 << 0; > const FLAG_2 = 1 << 1; > const FLAG_3 = 1 << 2; > const FLAG_4 = 1 << 3; > const FLAG_5 = 1 << 4; > const FLAG_6 = 1 << 5; > const FLAG_7 = 1 << 6; > } > > Julien

« previous php.internals (#68511) next »