Re: [RFC] Constant Scalar Expressions (with constants)
| From: | Bob Weinand | Date: | Thu, 07 Nov 2013 12:45:25 +0000 |
| Subject: | Re: [RFC] Constant Scalar Expressions (with constants) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70052@lists.php.net to get a copy of this message | ||
Hi Lars,
In what way is this ambiguous?
I just tested; FOO never equals self::FOO. FOO always is a global constant, while self::FOO (and
Klass::FOO) is the only way to refer to the class constant.
const FOO = 2;
class Klass
{
const FOO = 1;
const BAR = FOO; // value two, global constant, and if FOO is not defined, Klass::Bar ===
"FOO".
}
Bob
Am 7.11.2013 um 13:31 schrieb Lars Strojny <lars@strojny.net>:
> Hi Bob,
>
> thanks for your work, it’s awesome. One thing about constants:
>
> Take this example:
>
> const FOO = 2;
>
> class Klass
> {
> const FOO = 1;
> const BAR = FOO;
> }
>
> Here FOO is ambiguous, as it could resolve to 2 or to 1. If I understood it correctly, global
> constants are not yet implemented but I would suggest to always force prefixing the constant to get
> rid of the ambiguity and allow for future extension.
>
> const FOO = 2;
>
> class Klass
> {
> const FOO = 1;
> const BAR = self::FOO;
> }
>
> Does that make sense?
>
> cu,
> Lars
>
> On 07 Nov 2013, at 13:01, Bob Weinand <bobwei9@hotmail.com> wrote:
>
>> Hi!
>>
>> As you all know, Anthony Ferrara had withdrawn his RFC a few months ago, which was without
>> support for constants in these expressions:
>>
>> const foo = 10;
>> const bar = 10 * foo;
>>
>> The use of a constant in a declaration of a constant was not yet possible with his patch.
>>
>> That's what I changed.
>>
>> Enjoy reading the RFC at:
>>
>> https://wiki.php.net/rfc/const_scalar_exprs
>>
>> Bob Weinand
>>
>> Special thanks go to Dmitry who had helped me a lot with feedback and a deep review of the
>> patch.
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php