|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
im puzzled. i use vbscript and c++ etc and they have enumerations. i can't find how to create an enum in php, does anyone have any ideas? i looked in the manual..no hope. i want something like this
var $myEnum {0 = 'red', 1 = 'blue', 2 = 'yellow'}; $d = new myEnum('blue'); i suppose i could use a class but its a waste if php does actually support enums. ![]() |
|
#2
|
|||
|
|||
|
Can you just use an array?
Consider: $myEnum = array ("red","blue","yellow"); $d = $myEnum[1]; |
|
#3
|
|||
|
|||
|
or maybe an associative array?
PHP Code:
I didn't see any direct references to enums in the PHP manual but I've never had much use for them... |
|
#4
|
|||
|
|||
|
i guess i could yeah...but im assuming that no one knows if php supports enums? if not its ok...an associative array will do. thanks guys
![]() |
|
#5
|
|||
|
|||
|
ENUM's don't exists in PHP. No real need for them, as PHP's arrays can pretty much handle the job.
|
|
#6
|
|||
|
|||
|
a decent workaround
I got to this thread trying to find out the same thing. I didn't really get my question answered, but I did think of a nasty workaround.
PHP Code:
|
|
#7
|
|||
|
|||
|
Howto Simulate Enumeration in PHP
Hey all,
This is how I implement enumeration in php. It is a little tighter then using an array so you have less bugs later. I can't post the link but you can look it up detailed explanation on my blog at wordpress. wshell.wordpress.com Here is the code... PHP Code:
Working Example Using Constructor: $shape = new Shape("Circle"); Working Example Using Set(): $shape = new Shape(); Exception Example Using Set(): $shape = new Shape(); Enjoy! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > php and enumerations |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|