How to call a constant as a function name?
constants, function, php
Solution
Since you asked for the why/reason I guess the only answer (which will probably not satisfy you) is: Because it hasn't been proposed, discussed and accepted on https://wiki.php.net/rfc .
Problem
In PHP, you can call functions by calling their name inside a variable. ``` function myfunc(){ echo 'works'; } $func = 'myfunc'; $func(); // Prints "works" ``` But, you can't do this with constants. ``` define('func', 'myfunc'); func(); // Error: function "func" not defined ``` There are workarounds, like these: ``` $f = func; $f(); // Prints "works" call_user_func(func); // Prints "works" function call($f){ $f(); } call(func); // Prints "works" ``` The PHP documentation on `callable` says: A PHP function is passed by its name as a string. Any built-in or user-defined function can be used, except language constructs. There seems to be nothing about constant values not being callable. I also tried to check it, and of course, ``` var_dump(is_callable(func)); ``` prints `bool(true)`. 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? 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 why PHP doesn't allow calling the function directly through the constant.