Re: [PATCH] Allow constant expressions

From: Date: Tue, 08 Apr 2003 21:22:57 +0000
Subject: Re: [PATCH] Allow constant expressions
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-811@lists.php.net to get a copy of this message
The last patch introduced a couple of bugs: 1) global constants weren't allowed, this includes true, false, null, etc. 2) it overrode the default behaviour for var $variable = someconstant; since we're folding these, such initialization cannot reasonably happen (big BC break). Attached is a new patch (hopefully the last one), which fixes these bugs and adds the new functionality. -Sterling On Tue, 2003-04-08 at 14:08, Sterling Hughes wrote: > Yargh, a little debug info got into the last patch. > > Attached is the last patch, minus my little debug stuff. > > > On Tue, 2003-04-08 at 14:05, Sterling Hughes wrote: > > Ok, attached is the updated patch, the result of a conversation between > > myself and Zeev. > > > > *) Class constants are allowed to be operands to constants. However, > > constants must exist within the current class only, and they must be > > defined before usage, so for example: > > > > class simple { > > const second = 1; > > const minute = 60 * second; > > const hour = 60 * minute; > > const day = 24 * hour; > > } > > > > Would work. > > > > However: > > > > class simple { > > const minute = second * 60; > > const second = 1; > > } > > > > Wouldn't, and neither would: > > > > class simple { > > const foo = "bar"; > > } > > > > class simple1 { > > const baz = "bar" . foo; > > } > > > > Currently, referencing the current class also doesn't work, ie, > > > > class simple { > > const bar = "baz"; > > const foo = simple::bar . "naz"; > > } > > > > Although that could be added. > > > > It is also important to note that const is now *fully* compile time, > > therefore const cannot, for example, reference a define() which is > > called above (because define() is runtime). > > > > Also, this patch removes the ability to use operators in array > > initialization, as a bunch of people seem to have found that behaviour > > distasteful. Patch attached. > > > > > > On Mon, 2003-04-07 at 22:43, Sterling Hughes wrote: > > > I've updated my patch (attached), which allows for parentheses groupings > > > such as : > > > > > > const foo = (1<<2) | (2 & 5); > > > > > > -Sterling > > > > > > On Mon, 2003-04-07 at 21:06, Sterling Hughes wrote: > > > > Hi, > > > > > > > > The attached patch allows constant expressions within class variables > > > > and constants. I came into this problem when I wanted the following > > > > sequence: > > > > > > > > class foo { > > > > const A = 1<<0; > > > > const B = 1<<1; > > > > const C = 1<<2; > > > > } > > > > > > > > And the current parser doesn't allow such rules. I therefore added the > > > > attached patch which allows operators to be used on constants within > > > > these expressions (and also within array declarations). This is > > > > achieved by folding statements such as '1<<0' into their > > > > equivalent > > > > values at compile time. The following operators are supported: << > > > > >> | > > > > & + - * / . % ^ ~ xor > > > > > > > > Please review it, and let me know if its ok to commit. :) > > > > > > > > -Sterling -- "Science is like sex: sometimes something useful comes out, but that is not the reason we are doing it." - Richard Feynman

Attachment: [text/x-patch] constant.diff
« previous php.internals (#811) next »