Re: [PATCH] Allow constant expressions

From: Date: Thu, 10 Apr 2003 06:59:03 +0000
Subject: Re: [PATCH] Allow constant expressions
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-831@lists.php.net to get a copy of this message
I think there's one broken thing in this patch (I haven't tested it, so I could be wrong) - it removes some functionality that we did have in the past. static_scalar can no longer contain a constant (one that was defined with define()). That means that constant initializers for arrays, default arguments, etc - lose a big chunk of functionality. (again, I arrived at that conclusion by briefly going over the parser patch, if you took this into account and it does work - go ahead and commit it, it looks good). Zeev At 21:05 08/04/2003, 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
-- "Nothing is particularly hard if you divide it into small jobs."
    - Henry Ford
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#831) next »