Following Richard's e-mail I created a patch and a RFC (
http://wiki.php.net/rfc/enum ) to introduce the enum language
structure.
Two patches are available on to create an enumeration as Richard's suggested
class foo {
const enum {
CASE_1,
CASE_2,
CASE_3,
CASE_4
};
}
And one other without the const keyword :
class foo {
enum {
CASE_1,
CASE_2,
CASE_3,
CASE_4
};
}
Every suggestions/feedback are welcome.
Pierrick
2010/5/20 Richard Quadling <[email protected]>:
> On 19 May 2010 22:18, Alban LEROUX <[email protected]> wrote:
>> On 2010-05-19 14:04:13 +0200, Ferenc Kovacs said:
>>
>>> On Wed, May 19, 2010 at 1:49 PM, Christian Schneider
>>> <[email protected]>wrote:
>>>
>>>> fqqdk wrote:
>>>>>
>>>>> How about extending the usage of the 'final' keyword to support a
>>>>
>>>> java-like
>>>>>
>>>>> syntax?
>>>>>
>>>>> class Foo {
>>>>> private static final $bar = 'ex' . 'pression';
>>>>
>>>> In my book "final" in Java gets an award for sickest abuse of a keyword.
>>>> So no, I don't consider this an option. Simply use a class variable (or
>>>> define()) if you need to store some runtime calculated value.
>>>>
>>>> "But <insert other language> can do this" alone is not sufficient as a
>>>> reason to bloat PHP IMHO.
>>>>
>>>> - Chris
>>>>
>>>
>>> I think that is pretty subjective, but I did suprised when I found out,
>>> that
>>> the global scope constants behaves differently than the class consts.
>>>
>>> Allowing the class consts to be initialized in runtime(if neccessary)
>>> wouldn't breake any php application, only slow them.
>>> Can't we do something, to allow broader usage of consts without
>>> sacrificing
>>> performance?
>>> So I propose to add a new syntax: literal.
>>> literal should behave how the const behaved, and const should be
>>> initialized
>>> in runtime.
>>> maybe we could check from runtime, that the const was a dynamic value, or
>>> literal, and generate a notice for the developer to change the const to
>>> literal for gaining performance.
>>>
>>> What do you think?
>>>
>>> Tyrael
>>
>> That's could be very useful to define flag, something like that :
>>
>> class foo {
>> const CASE_1 = 1 << 1;
>> const CASE_2 = 1 << 2;
>> const CASE_3 = 1 << 3;
>> const CASE_4 = 1 << 4;
>> ....
>> }
>> --
>> Alban Leroux
>> [email protected]
>> Web developper
>>
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> For this, an enumerator could be an option. I would certainly use this
> a LOT for many sort of statuses within my code.
>
> class foo {
> const enum {
> CASE_1,
> CASE_2,
> CASE_3,
> CASE_4
> };
> }
>
> maybe.
>
> --
> -----
> Richard Quadling
> "Standing on the shoulders of some very clever giants!"
> EE : http://www.experts-exchange.com/M_248814.html
> EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
> ZOPA : http://uk.zopa.com/member/RQuadling
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php