On 22.08.2007 21:08, Stanislav Malyshev wrote:
>> Don't you think it's bad idea to use the same 'const' syntax, but
>> different behavior?
>> I believe it would be really confusing for users, as class constants are
>> set in compile time, thus 'const DIR = dirname(__FILE__);' is not possible.
>
> That's a good point. However, "constant constants" - i.e., ones not
> allowing expressions - would be much less useful, since many uses of the
> constants - as used by define() - imply runtime evaluation - such as
> pathes, configuration-derived variables, etc.
Which basically means class constants are useless in their current state, right?
> On the other hand, const in classes indeed doesn't allow us to define
> runtime expressions. This is, however, offset by the fact that we have
> per-class variables, where we can store expressions. In namespaces we
> don't have (and probably don't want) per-namespace variables, so if you
> need to keep something like dirname(__FILE__) somewhere inside
> namespace, you have no option.
> We could try to solve this by changing const to some other keyword. The
> downside would be that we'd have further complicated the syntax. We
> could modify define() or add ns_define() which would automagically add
> namespace prefix. More options?
>
> If anybody has any good idea of how to solve this, suggestions are
> welcome. The summary of the problem is as follows:
> 1. We need some syntax to define per-namespace values.
> 2. For these values are to be useful they should allow runtime definition
I don't think it's _required_ for the constants to be useful.
It would be good to have, but not required.
I prefer consistent behavior vs inconsistency with more features.
> 3. const syntax looks like class constants which allow only compile-time
> definition
--
Wbr,
Antony Dovgal