Why can string become a function in PHP?


In the example I have a function with the name of a funcao , which is intended only to display the parameter's value on the screen.

When creating a string with the name of the function and calling it as a function, it will be executed:


function funcao($parametro = "default") {
    echo $parametro . "<br/>\n" ;

$func = "funcao"; 

$func = "FUNCAO";


See on Ideone

Why does it happen that I can call the function in the following way?


the same works with variable variables, the name is a little strange, but it exists as in the example below:

$vara = "c";
$varb = "vara";
echo $$varb;


This happens because you can use the value of a variable to call functions, or access other variables, thus ensuring greater flexibility in the language.

How does PHP interpret the last line?

echo $$varb;

replaces the first variable by its value ($varb per stick);

echo $vara;

replaces the second variable by its value ($vara by c);

echo c;

and prints the value on the screen

Scroll to Top