update page now
International PHP Conference Berlin 2026

Voting

: one minus one?
(Example: nine)

The Note You're Voting On

niemans at pbsolo dot nl
6 years ago
While the documentation suggests that the use of a constant is similar to the use of a variable, there is an exception regarding variable functions. You cannot use a constant as the function name to call a variable function.

const DEBUGME ='func';
function func($s) { echo $s. "\n"; }

DEBUGME('abc');  // results in a syntax error

$call = DEBUGME;
$call('abc');          // does the job

But you can use a constant as an argument to a function. Here's a simple workaround when you need to call a variable constant function: 

function dynamic($what, $with)
   {
     $what($with);
   }
dynamic(DEBUGME, 'abc'); 

This makes sense to me to hide API's and/or long (complicated) static calls.
Enjoy!

<< Back to user notes page

To Top