It is possible to create sets of enumeration types in PHP like in Delphi?  I want to create a set of options for a component like [required, readonly, ...]. I've seen  but it does not solve my problem completely.  For intance, in Delhpi you can do something like:  type enum_options = (required, readonly, ...); // Enumerated type options_for_my_component := [required, readonly]; ... if (required in options_for_my_component) then    ...   More info at
220
I know that PHP doesn't yet have native Enumerations. But I have become accustomed to them from the Java world. I would love to use enums as a way to give predefined values which IDEs' auto-completion features could understand. Constants do the trick, but there's the namespace collision problem and (or actually because) they're global. Arrays don't have the namespace problem, but they're too vague, they can be overwritten at runtime and IDEs rarely know how to autofill their keys without additional static analysis annotations or attributes. Are there any solutions/workarounds you commonly use? Does anyone recall whether the PHP guys have had any thoughts or decisions around enumerations?
99253
I like how Java has a Map where you can define the types of each entry in the map, for example &lt;String, Integer&gt;.   What I'm looking for is a type of collection where each element in the collection is a pair of values.  Each value in the pair can have its own type (like the String and Integer example above), which is defined at declaration time.    The collection will maintain its given order and will not treat one of the values as a unique key (as in a map).    Essentially I want to be able to define an ARRAY of type &lt;String,Integer&gt; or any other 2 types.    I realize that I can make a class with nothing but the 2 variables in it, but that seems overly verbose.    I also realize that I could use a 2D array, but because of the different types I need to use, I'd have to make them arrays of OBJECT, and then I'd have to cast all the time.    I only need to store pairs in the collection, so I only need two values per entry.  Does something like this exist without going the class route?  Thanks!
30702
Is there a way of using an 'OR' operator or equivalent in a PHP switch?  For example, something like this:  switch ($value) {      case 1 || 2:         echo 'the value is either 1 or 2';         break; }
1080
How can you enumerate an enum in C#?  E.g. the following code does not compile:  public enum Suit {     Spades,     Hearts,     Clubs,     Diamonds }  public void EnumerateAllSuitsDemoMethod() {     foreach (Suit suit in Suit)     {         DoSomething(suit);     } }   And it gives the following compile-time error:     'Suit' is a 'type' but is used like a 'variable'   It fails on the Suit keyword, the second one.
2310
In Ruby you can easily set a default value for a variable   x ||= "default"   The above statement will set the value of x to "default" if x is nil or false  Is there a similar shortcut in PHP or do I have to use the longer form:  $x = (isset($x))? $x : "default";   Are there any easier ways to handle this in PHP?
4407
I know this rather goes against the idea of enums, but is it possible to extend enums in C#/Java?  I mean "extend" in both the sense of adding new values to an enum, but also in the OO sense of inheriting from an existing enum.    I assume it's not possible in Java, as it only got them fairly recently (Java 5?).  C# seems more forgiving of people that want to do crazy things, though, so I thought it might be possible some way.  Presumably it could be hacked up via reflection (not that you'd every actually use that method)?  I'm not necessarily interested in implementing any given method, it just provoked my curiosity when it occurred to me :-)
43991
I have the following enumeration:  public enum AuthenticationMethod {     FORMS = 1,     WINDOWSAUTHENTICATION = 2,     SINGLESIGNON = 3 }   The problem however is that I need the word "FORMS" when I ask for AuthenticationMethod.FORMS and not the id 1.  I have found the following solution for this problem ():  First I need to create a custom attribute called "StringValue":  public class StringValue : System.Attribute {     private readonly string _value;      public StringValue(string value)     {         _value = value;     }      public string Value     {         get { return _value; }     }  }   Then I can add this attribute to my enumerator:  public enum AuthenticationMethod {     [StringValue("FORMS")]     FORMS = 1,     [StringValue("WINDOWS")]     WINDOWSAUTHENTICATION = 2,     [StringValue("SSO")]     SINGLESIGNON = 3 }   And of course I need something to retrieve that StringValue:  public static class StringEnum {     public static string GetStringValue(Enum value)     {         string output = null;         Type type = value.GetType();          //Check first in our cached results...          //Look for our 'StringValueAttribute'           //in the field's custom attributes          FieldInfo fi = type.GetField(value.ToString());         StringValue[] attrs =            fi.GetCustomAttributes(typeof(StringValue),                                    false) as StringValue[];         if (attrs.Length &gt; 0)         {             output = attrs[0].Value;         }          return output;     } }   Good now I've got the tools to get a string value for an enumerator. I can then use it like this:  string valueOfAuthenticationMethod = StringEnum.GetStringValue(AuthenticationMethod.FORMS);   Okay now all of these work like a charm but I find it a whole lot of work. I was wondering if there is a better solution for this.  I also tried something with a dictionary and static properties but that wasn't better either.
73828
I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enum that is 64 bits wide?
17843
Question based on .  Let's say we have some C# classes with HelpAttribute in standalone desktop application. Is it possible to enumerate all classes with such attribute? Does it make sense to recognize classes this way? Custom attribute would be used to list possible menu options, selecting item will bring to screen instance of such class. Number of classes/items will grow slowly, but this way we can avoid enumerating them all elsewhere, I think.
27641
I currently have my PHP class variables set up like this:  class someThing {      private $cat;     private $dog;     private $mouse;     private $hamster;     private $zebra;     private $lion;      //getters, setters and other methods }   But I've also seen people using a single array to store all the variables:  class someThing {      private $data = array();      //getters, setters and other methods }   Which do you use, and why? What are the advantages and disadvantages of each?
30409
I am using the , and have defined lstset parameter sets for multiple programming languages. I would like to select a parameter set when beginning a lstlisting or lstinputlisting by selecting the language corresponding to the parameter set definitions. I appreciate, however, that language selection at this stage only affects formatting of language-specific syntax and is not connected to the preamble parameter set definitions. Rather, enumerating multiple such definitions is fruitless as the last set of definitions overrides all the former ones (or so it appears). Therefore, I would like to know how to define and subsequently invoke multiple lstset parameter sets.  As a very rudimentary example,  \documentclass{article} \usepackage{listings}% http://www.ctan.org/pkg/listings \lstset{language=C,frame=lines} \lstset{language=C++,frame=none} \begin{document} \begin{lstlisting}[language=C] #include&lt;stdio.h&gt; main() {  printf("Hello World"); } \end{lstlisting} \begin{lstlisting}[language=C++] #include &lt;iostream.h&gt; main() {  cout &lt;&lt; "Hello World!";  return 0; } \end{lstlisting} \end{document}   As one can see, both languages are displayed using the second defined parameter set (frame=none). I would like to use a key-value pair in the \begin{lstlisting} macro to invoke the appropriate language-specific parameter set defined in the preamble (as suggested by my use of the language= key-value pair). Is this possible?
81854
When I define an object of a class using new like this  $blah = new Whatever();   I get autocomplete for $blah. But how do I do it when I have $blah as a function parameter? Without autocomplete I am incomplete.  Edit: How do I do it if it's in an include and PDT or Netbeans can't figure it out? Is there any way to declare types for variables in PHP?
54259
I thought I had tamed enumitem. I had this  and this .  Then I tried a [&lt;+-&gt;] construct. It failed. Commmenting the enumitem section prevents errors but I'd rather not have to do this.  On its current state, this code produces two errors, one because of the [&lt;+-&gt;] and another because of the \onslide.   \documentclass{beamer}   \usepackage{enumitem}  \setitemize{label=\usebeamerfont*{itemize item}%    \usebeamercolor[fg]{itemize item}    \usebeamertemplate{itemize item}}%https://tex.stackexchange.com/a/24491  \setenumerate[1]{%    label=\protect\usebeamerfont{enumerate item}%          \protect\usebeamercolor[fg]{enumerate item}%          \insertenumlabel.}%https://tex.stackexchange.com/a/45950   \begin{document}  \begin{frame}  \begin{itemize}[&lt;+-&gt;]  \item 1  \item 2  \end{itemize}  \onslide&lt;2&gt;{text}  \end{frame}  \end{document}
92538
I'd like to create a Dictionary object, with string Keys, holding values which are of a generic type. I imagine that it would look something like this:  Dictionary&lt;string, List&lt;T&gt;&gt; d = new Dictionary&lt;string, List&lt;T&gt;&gt;();     And enable me to add the following:  d.Add("Numbers", new List&lt;int&gt;()); d.Add("Letters", new List&lt;string&gt;());   I know that I can do it for a list of strings, for example, using this syntax:  Dictionary&lt;string, List&lt;string&gt;&gt; d = new Dictionary&lt;string, List&lt;string&gt;&gt;(); d.Add("Key", new List&lt;string&gt;());   but I'd like to do it for a generic list if possible...  2 questions then:   Is it possible? What's the syntax?   Many thanks, Jon
18458
How to make enumerate list format numbers like this:     REG/001 (content)      REG/002 (content)      REG/003 (content)   I already managed to do the following:   \begin{enumerate}[label=\textbf{REG/\arabic*},leftmargin=*] \item content \end{enumerate}   using   \usepackage{enumitem}   but I don't know how to add leading zeros.
19825
But here's an example:  Dim desiredType as Type if IsNumeric(desiredType) then ...   EDIT: I only know the Type, not the Value as a string.  Ok, so unfortunately I have to cycle through the TypeCode.  But this is a nice way to do it:   if ((desiredType.IsArray))       return 0;   switch (Type.GetTypeCode(desiredType))  {       case 3:       case 6:       case 7:       case 9:       case 11:       case 13:       case 14:       case 15:           return 1;  }  ;return 0;
45776
I'm trying to do something like the following:  enum E;  void Foo(E e);  enum E {A, B, C};   which the compiler rejects.  I've had a quick look on Google and the consensus seems to be "you can't do it", but I can't understand why.  Can anyone explain?  Clarification 2: I'm doing this as I have private methods in a class that take said enum, and I do not want the enum's values exposed - so, for example, I do not want anyone to know that E is defined as  enum E {     FUNCTIONALITY_NORMAL, FUNCTIONALITY_RESTRICTED, FUNCTIONALITY_FOR_PROJECT_X }   as project X is not something I want my users to know about.  So, I wanted to forward declare the enum so I could put the private methods in the header file, declare the enum internally in the cpp, and distribute the built library file and header to people.  As for the compiler - it's GCC.