THRIFT-659. php: Make php_thrift_protocol handle std::exception cleanly

Any std::exceptions thrown from within the extension will now be
converted into php exceptions.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920662 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
index 6844fb3..e6ba94a 100644
--- a/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
+++ b/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
@@ -399,6 +399,12 @@
   throw PHPExceptionWrapper(ex);
 }
 
+// Sets EG(exception), call this and then RETURN_NULL();
+void throw_zend_exception_from_std_exception(const std::exception& ex) {
+  zend_throw_exception(zend_exception_get_default(TSRMLS_CC), const_cast<char*>(ex.what()), 0 TSRMLS_CC);
+}
+
+
 void binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport, zval* return_value, HashTable* fieldspec) {
   zval** val_ptr;
   Z_TYPE_P(return_value) = IS_NULL; // just in case
@@ -927,6 +933,9 @@
   } catch (const PHPExceptionWrapper& ex) {
     zend_throw_exception_object(ex TSRMLS_CC);
     RETURN_NULL();
+  } catch (const std::exception& ex) {
+    throw_zend_exception_from_std_exception(ex);
+    RETURN_NULL();
   }
 }
 
@@ -1000,6 +1009,9 @@
   } catch (const PHPExceptionWrapper& ex) {
     zend_throw_exception_object(ex TSRMLS_CC);
     RETURN_NULL();
+  } catch (const std::exception& ex) {
+    throw_zend_exception_from_std_exception(ex);
+    RETURN_NULL();
   }
 }