resume after exception

From: Date: Mon, 02 Apr 2012 12:44:12 +0000
Subject: resume after exception
Groups: php.internals 
Request: Send a blank email to internals+get-59323@lists.php.net to get a copy of this message
I was just reading about the new async/await keywords in C# 5.0, and while this has no particular relevance to PHP as such, it got me thinking about this idea... What if you could resume execution after an exception was thrown? Fictive example: function test() { echo "Begin Test!\n"; throw new Interrupt(); echo "Execution resumed!"; } try { test(); } catch (Interrupt $e) { echo "Execution interrupted.\n"; resume; } The output of this would be: Begin Test! Execution interrupted. Execution resumed! In other words, Interrupt is a new type of Exception, from which you can recover, using the new resume keyword. Taking this one step further, imagine it were also possible to serialize() an Interrupt - and resume it at a later time. This would open up entirely new possibilities for (AJAX) web-application frameworks, which would be able to suspend execution, serialize the script state, return a response, wait for further interaction from the user, and then resume execution. I'm sure there are lots of problems with this idea, and perhaps it's not a good fit for PHP at all, but I figured it couldn't harm to put the idea out there anyway :-) Any thoughts?

« previous php.internals (#59323) next »