|
Post by Eric on Mar 30, 2006 1:08:42 GMT
|
|
|
Post by acoolie530 on Mar 30, 2006 22:49:15 GMT
I never used enums, but from the looks of this, you can set variables in the class, then you have to enter a string of one of the variables to get the value?
Please give a real-world example, because I have no idea what good this does.
|
|
|
Post by Eric on Mar 30, 2006 22:54:08 GMT
I never used enums, but from the looks of this, you can set variables in the class, then you have to enter a string of one of the variables to get the value? Please give a real-world example, because I have no idea what good this does. What are you talking about? Elaborate. There are 2 classes present
|
|
|
Post by acoolie530 on Mar 30, 2006 23:23:00 GMT
I want an example on usage in a real code, not a usage example.
Anyways, from the looks of it, you first define some variables in Enum constructor, then you can grab the values of them later by using the e_var::set and e_var::get functions?
I don't see the real point in that.
|
|
|
Post by Eric on Mar 30, 2006 23:35:39 GMT
Its purpose is to stop the assigning of invalid values. Its like here's a variable type and here are its possible values.
In the first constructor you are defining the type, in the second constructor you are making an instance of that type.
You can then variate through them. However to make it work properly and disable direct setting I had to make it a private variable and use functions.
Much like in the database fields there is enum, so if you are only going to use the values of 1 and 0 (true and false) then you define it as such.
|
|
|
Post by [dmsuperman] on Mar 31, 2006 21:05:57 GMT
Very good idea... is this already a feature in PHP? If not I'm going to create my own and beging using it, excellent idea as it's good for security and such, and it saves a bunch of if statements. It would be good to like have a default such as the first value rather than throw an error. Also, instead of several instances of one class (I think it's a performance issue in PHP) you could store them all in one array, like enum.varname1 and enum.varname2 where you can use enum.varname1.get and such...know what I mean? I guess it kind of makes it neater too then, because you differentiate between enums and normal vars.
|
|
|
Post by Eric on Apr 1, 2006 0:12:06 GMT
Very good idea... is this already a feature in PHP? If not I'm going to create my own and beging using it, excellent idea as it's good for security and such, and it saves a bunch of if statements. It would be good to like have a default such as the first value rather than throw an error. Also, instead of several instances of one class (I think it's a performance issue in PHP) you could store them all in one array, like enum.varname1 and enum.varname2 where you can use enum.varname1.get and such...know what I mean? I guess it kind of makes it neater too then, because you differentiate between enums and normal vars. Aye. Though I don't think PHP supports it defaultly. It does have a default value though, its default is 0, or the start of the array. Hence var value = parent.pos_vals[parent.default_val];
|
|
|
Post by acoolie530 on Apr 1, 2006 0:15:48 GMT
Not sure if Dmsuperman showed you this or not, but Link and Linkeh
|
|
|
Post by Eric on Apr 1, 2006 3:43:54 GMT
Not sure if Dmsuperman showed you this or not, but Link and LinkehNope .
|
|
|
Post by [dmsuperman] on Apr 1, 2006 4:23:28 GMT
You weren't on...
|
|