0

I am just amazed that why below code does not work

function test(){
  echo "this is test";
}

function getName($f)
{
  return $f;
}

getName("test")();

It works when I put function name in variable like this

$f = getName("test");
$f();

What could be the reason?

Mohd Shahid
  • 1,538
  • 2
  • 33
  • 66

1 Answers1

2

that's not possible to call a multiple functions directly, you must have to store return values to other function and then try to call other function.

Instead, if you want to access multiple functions at a same time just call other function in the first function. See below code for your reference

 function test() {
      echo "this is test";
    }

    function getName($f) {
        $a = $f();
        return $a;
    }
    getName("test");
user1844933
  • 3,296
  • 2
  • 25
  • 42
Keyur Mistry
  • 926
  • 6
  • 18
  • 1
    That actually not entirely true anymore... http://stackoverflow.com/questions/3724112/php-method-chaining gives examples. – Jon Apr 19 '14 at 07:06