Calling PHP functions within HEREDOC strings

If you really want to do this but a bit simpler than using a class you can use:

function fn($data) {
  return $data;
}
$fn = 'fn';

$my_string = <<<EOT
Number of seconds since the Unix Epoch: {$fn(time())}
EOT;

Leave a Comment