summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Schoenmakers <toon.schoenmakers@copernica.com>2015-10-08 11:04:54 +0200
committerToon Schoenmakers <toon.schoenmakers@copernica.com>2015-10-08 11:04:54 +0200
commit780a9445afc58a46a6c1e4dd3c4b5a4ce7f03042 (patch)
tree80dfbaedd6c4027ee4470e217eb859b7af7ba8eb
parent0ef1b5e130f300dab0ae06b67b44b33da7274a97 (diff)
Properly handle a Php::Exception when thrown from a serialize method
-rw-r--r--zend/classimpl.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/zend/classimpl.cpp b/zend/classimpl.cpp
index ad7dab4..30c90c9 100644
--- a/zend/classimpl.cpp
+++ b/zend/classimpl.cpp
@@ -1260,14 +1260,27 @@ int ClassImpl::serialize(zval *object, unsigned char **buffer, zend_uint *buf_le
// get the serializable object
Serializable *serializable = dynamic_cast<Serializable*>(ObjectImpl::find(object TSRMLS_CC)->object());
- // call the serialize method on the object
- auto value = serializable->serialize();
-
- // allocate the buffer, and copy the data into it (the zend engine will
- // (hopefully) clean up the data for us - the default serialize method does
- // it like this too)
- *buffer = (unsigned char*)estrndup(value.c_str(), value.size());
- *buf_len = value.size();
+ // user may throw an exception in the serialize() function
+ try
+ {
+ // call the serialize method on the object
+ auto value = serializable->serialize();
+
+ // allocate the buffer, and copy the data into it (the zend engine will
+ // (hopefully) clean up the data for us - the default serialize method does
+ // it like this too)
+ *buffer = (unsigned char*)estrndup(value.c_str(), value.size());
+ *buf_len = value.size();
+ }
+ catch (Exception &exception)
+ {
+ // user threw an exception in its method
+ // implementation, send it to user space
+ process(exception TSRMLS_CC);
+
+ // unreachable
+ return FAILURE;
+ }
// done
return SUCCESS;