|
Posted by gosha bine on 08/02/07 08:21
On 02.08.2007 04:55 Yarco wrote:
> Array is the very basic type in php i think. So why const keyword
> doesn't support such defination grammar?
>
> class Date
> {
> const char3 = array(1 => 'Jan', ...); // ??
> }
>
> So how can i do somthing like c++'s enum?
>
> class Data
> {
> const Jan = 1;
> //...
> }
>
> is poor if i want to chanslate number to month name.
>
The reason of disabling arrays was that parser wasn't able to parse
"someConst[key]" correctly.
http://bugs.php.net/bug.php?id=25816
As to enums, they are used in C to give symbolic names to integer
constants. In php constants don't have to be integer, that is we can
simply use strings instead of symbolic names:
// c way
const BY_NAME = 1;
....
if($sort_mode == BY_NAME) ...
// php way
if($sort_mode == 'BY_NAME') ...
ruby's interned strings (:BY_NAME) would be even better, unfortunately
php doesn't support this
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Navigation:
[Reply to this message]
|