title: How to call a constant as a function name?
body: <p>In PHP, you can call functions by calling their name inside a variable.</p>
  
  <pre class="lang-php prettyprint-override"><code>function myfunc(){ echo 'works'; }
  
  $func = 'myfunc';
  $func(); // Prints "works"
  </code></pre>
  
  <p>But, you can't do this with constants.</p>
  
  <pre class="lang-php prettyprint-override"><code>define('func', 'myfunc');
  
  func(); // Error: function "func" not defined
  </code></pre>
  
  <p>There are workarounds, like these:</p>
  
  <pre class="lang-php prettyprint-override"><code>$f = func;
  $f(); // Prints "works"
  
  call_user_func(func); // Prints "works"
  
  function call($f){ $f(); }
  call(func); // Prints "works"
  </code></pre>
  
  <p>The PHP documentation on <a href="http://fi2.php.net/manual/en/language.types.callable.php" rel="nofollow noreferrer"><strong><code>callable</code></strong></a> says:</p>
  
  <blockquote>
    <p>A PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs.</p>
  </blockquote>
  
  <p>There seems to be nothing about constant values not being callable.</p>
  
  <p>I also tried to check it, and of course,</p>
  
  <pre class="lang-php prettyprint-override"><code>var_dump(is_callable(func));
  </code></pre>
  
  <p>prints <code>bool(true)</code>.</p>
  
  <p>Now, is there an explanation as to why is it this way? As far as I can see all the workarounds rely on assigning the constant value to a variable, by why can't constant be called?</p>
  
  <p><strong>And again, just to make it super clear, I don't need a way to call the function, I even presented some there. I want to know <em>why</em> PHP doesn't allow calling the function directly through the constant.</strong></p>