You are here: Re: PHP Enumerations? « PHP Programming Language « IT news, forums, messages
Re: PHP Enumerations?

Posted by Oli Filth on 11/07/05 03:16

Seamus M said the following on 06/11/2005 22:40:
> I can't find any info on enumerations in the PHP manual, so I assume there
> is no built in way to create them. Can anyone tell me the best way to build
> a simple enumeration, such as:
>
> Enum AllItems as Integer
>
> 'First Item' = 1;
> 'Second Item' = 2;
> :
> End Enum
>

PHP does not have enumerations per se.

I guess the closest thing you could do (assuming PHP 5) is an abstract
class with constants, e.g.:

abstract class AllItems
{
const Dog = 1;
const Cat = 2;
const Ocelot = 3;
}

echo AllItems::Dog; // displays "1"


--
Oli

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация