First of all your code has errors:
echo JSON.encode("data" => eval($_GET['func']));
There's no JSON.encode in PHP. The correct function is json_encode. You also have to pass a valid value, like an array:
echo json_encode(["data" => eval($_GET['func'])]);
That being said. Don't use eval unless there's absolutely no other way, because:
Caution: The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.
However, your code has a major security flaw. You pass everything from a $_GET parameter to eval(). You don't verify that string at all. I can call your script like:
callPhp.php?func=return system("ls -a");
… and I will get a list of all files in the directory. And this is just an example, because now anybody can run any code on your server. I can get your database content, download files, run scripts, send emails etc.
To be sure, let me put it this way:
Don't use that code.
If your goal is to run a function based on a selection in the client, send over a string, test it, and call the requested function yourself:
$func = $_GET['func'];
if ('list-something' == $func) {
$data = listSomething();
}
This is just a simple example, to get you away from eval.
JSON.encode()in PHP? \$\endgroup\$