Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Except if your given code is not part of some kind of StatType class and is dealing internally with the representation of stat type states my answer might be missing the point a bit, but in any case here it is.</p> <p>In fact you are doing something wrong here and what you are asking is to find a way to workaround the essential problem you are having. Instead, you should fix the essential problem.</p> <p>Essential problem is that you are missing one layer of abstraction which will sit between the way you are representing your statType and the way you are using it.</p> <p>So, your program should not care if you call your statType: </p> <blockquote> <p>"TOTAL" or '"TOTAL"' or "Total" or "total"</p> </blockquote> <p>What you need to care is that your statType is in certain state in one moment of program execution. How that representation of the state is implemented ( a string with quotes or a number) is detail of implementation and your switch statement should not care about it.</p> <p>What happens if you decide to change your statTypeName to be without quotes for example. Than you'll have to go to every line of code that depended on it having quotes and to change it. If you would hide the implementation details in some way you would not need to change more than one line of code.</p> <p>Maybe one approach to setting abstraction around statTypes? (simplified for clarity)</p> <pre><code>class StatType { const TOTAL = 0; const VALUE = 1; // etc. } switch ($statType-&gt;type()) { case StatType::TOTAL: echo "&lt;br&gt;TOTAL"; break; case StatType::VALUE: echo "&lt;br&gt;VALUE"; break; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload