This generally isn't easily possible with PHP running in a web environment. There may be various "hacky" methods of accomplishing this, however they will be unreliable such as calling the function in a destructor, or using register_shutdown_function()
In reality the simple answer would be:
function foo()
{
$this->load_function_a();
echo 'A succesfully called';
$this->load_function_b();
}
However I'm assuming this won't suite your needs in your real code. So to solve this problem properly, the real answer would be to use some kind of queue and a queue processor. For example:
- Having function B queue it's functionality and then later processed by a cron job.
- Using something such a RabbitMQ or Gearman to process function B's functionality asynchronously.
Hope this helps!