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 5 9440
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
Oli Filth wrote: Seamus M said the following on 06/11/2005 22:40: I can't find any info on enumerations in the PHP manual
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"
Or an associative array perhaps?
$allitems = array('cat' => 1, 'dog' => 2, 'fish' => 3);
echo $allitems['cat'];
Or constants, but they are not restricted to one type or container:
define('ALL_CAT', 1);
define('ALL_DOG', 2);
define('ALL_FISH', 3);
echo ALL_CAT;
--
E. Dronkert
"Ewoud Dronkert" <fi*******@lastname.net.invalid> wrote in message
news:iu********************************@4ax.com... Oli Filth wrote: Seamus M said the following on 06/11/2005 22:40: I can't find any info on enumerations in the PHP manual
Or constants, but they are not restricted to one type or container:
define('ALL_CAT', 1); define('ALL_DOG', 2); define('ALL_FISH', 3); echo ALL_CAT;
You can get closer to the 'auto-increment' characteristic of true ENUM's by:
$n = 0;
define( 'ALL_CAT', $n++ );
define( 'ALL_DOG', $n++ );
define( 'ALL_FISH', $n++ );
I suspect most C programmers, seeing the above, would say "Aha, it's an
enumeration", which is really what one is after, I think.
================================================== ======================
Dana Cartwright wrote: You can get closer to the 'auto-increment' characteristic of true ENUM's by:
$n = 0; define( 'ALL_CAT', $n++ ); define( 'ALL_DOG', $n++ ); define( 'ALL_FISH', $n++ );
I suspect most C programmers, seeing the above, would say "Aha, it's an enumeration", which is really what one is after, I think.
Keeping with cat=1, dog=2, and fish=3, shouldn't that be either:
$n = 1;
....or...
$n = 0;
define('ALL_CAT', ++$n);
....etc?
- Ryan
"Ryan Lange" <cl*********@gmail.com> wrote in message
news:Ie********************@comcast.com... ================================================== ====================== Dana Cartwright wrote: You can get closer to the 'auto-increment' characteristic of true ENUM's by:
$n = 0; define( 'ALL_CAT', $n++ ); define( 'ALL_DOG', $n++ ); define( 'ALL_FISH', $n++ );
Keeping with cat=1, dog=2, and fish=3, shouldn't that be either:
$n = 1;
...or...
$n = 0; define('ALL_CAT', ++$n);
C enumerations start at zero, which is why I wrote it that way. The OP
talked about enumerations, and I was staying with that spirit. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joyce |
last post by:
In my schema I have 2 enumerations, let's say, country description and
country code, and I want to use them so I can map each country
description to its precise country code (and no other).
So far...
|
by: Plinkerton |
last post by:
I'm making an Base Class that will be inherited. In my base class, I
have a public enumeration that defines a list of things I want my class
to be able to do. I use it for Method input...
|
by: Christopher Benson-Manica |
last post by:
I'll try to explain what I want to do:
I have foo.h and foo.cpp. Units that include foo.h will define an
enumeration bar:
enum bar { typeNone, typeBaz, typeQuux, ... , count };
A method...
|
by: JoeH |
last post by:
Hi,
I'm using a COM DLL (created in VB) in my javascript code and can
successfully call its methods and get/set its properties. There are
also some Public enumerations defined in the ActiveX...
|
by: someone else |
last post by:
I have some code that creates dynamic enumerations for use in a PropertyGrid
control. This all works perfectly but the memory usage of the program
increases quite quicly when viewing the...
|
by: Oleg Ogurok |
last post by:
Hi all,
I've added a new DataSet (xsd file) to my project in VS.NET 2003.
There I create a simple type as an enumeration of values.
<xs:simpleType name="MyCustomType">
<xs:restriction...
|
by: ChrisB |
last post by:
Hello:
I will be creating 50+ enumerations related to a large number of classes
that span a number of namespaces. I was wondering if there are any "best
practices" when defining enumerations.
...
|
by: Ben Finney |
last post by:
Antoon Pardon wrote:
> I just downloaded your enum module for python
> and played a bit with it. IMO some of the behaviour makes it less
> usefull.
Feedback is appreciated. I'm hoping to...
|
by: Ben Finney |
last post by:
Howdy all,
PEP 354: Enumerations in Python has been accepted as a draft PEP. The
current version can be viewed online:
<URL:http://www.python.org/peps/pep-0354.html>
Here is the...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |