Subject says it all.
I want to make a small "ScopeGuard" library for exception-safe
transactions, like the following:
$scope = new ScopeGuard;
$scope->onSucces(function() { logTransactionOne(); });
$scope->onFailure(function() { rollbackTransationOne(); });
doTransactionOne();
$scope->onSuccess(function() { logTransactionTwo(); });
$scope->onFailure(function() { rollbackTransactionTwo(); });
$scope->onFailure(function() { logFailureOfTransactionTwo(); });
doTransactionTwo();
// ... Three Four etc...
So if an exception is thrown the attached onFailure callbacks will be
executed, if the scope is exited through a return however the success
callbacks will be executed.
This requires me to know in ScopeGuard::__destruct() if the scope was
left normally or due to an exception.
The code in https://github.com/php/php-src/blob/master/Zend/zend_objects.c#L135
(line 135) seems to prevent me from knowing that information, because
the exception is temporarily removed from the globals and put in a
local variable.
Is there any way to detect if an exception is currently in flight?
(I've asked this same question on SO last week:
http://stackoverflow.com/questions/33199997/in-destruct-how-can-you-see-if-an-exception-is-currently-in-flight)
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php