title: PHP: Shorthand Switch
body: <p>I'm looking for more comfortable/more short version of <code>Switch()</code> statement in case of using multiple functions.</p>
  
  <p>I'll give you one example: imagine 100-200 functions in one class, and you want to call only one of them by setting value to <code>id</code> in that class.</p>
  
  <p>In my particular case, I have the following structure of PHP file:</p>
  
  <pre><code>&lt;?php
  
    class _main
    {
        function request($id)
        {
            switch($id)
            {
                case 0:
                    $this-&gt;writeA();
                break;
                case 1:
                    $this-&gt;writeB();
                break;
  
                ///...
                // then we have 100-200 functions like this in switch.
            }
        }
        function writeA()
        {
            echo('a');
        }
        function writeB()
        {
            echo('b');
        }
    }
  
    $id   = 1;
    $x    = new _main();
    $x-&gt;request($id);
  
  ?&gt;
  </code></pre>
  
  <p>For some of you it may seem weird, but I don't want to have that much lines of code with <code>case</code> and <code>break</code>. For me, they are just making code more difficult to read.</p>
  
  <p>(by the way, writing it 100 times will not making it fun for me too).</p>
  
  <hr>
  
  <p><strong>CONCLUSION</strong></p>
  
  <ul>
  <li><p>What could be the best,fast and comfortable method?</p></li>
  <li><p>Can I store functions to array and then call them?</p></li>
  <li><p>And will it affect performance? Will be <code>Swicth()</code> even faster?</p></li>
  </ul>
  
  <p>Thank you :)</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Perhaps there is a different way of thinking/coding and not only array/switch thing.</p>