summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Schoenmakers <toon.schoenmakers@copernica.com>2015-09-16 18:22:59 +0200
committerToon Schoenmakers <toon.schoenmakers@copernica.com>2015-09-16 18:22:59 +0200
commit2df547bfd3caf93d36b3775f3e748ad52f6e422b (patch)
tree6c349c4e21bf36eb3d1df5066db7789c6cd4c41e
parentfa9b3f12ef210e1321b739437e10d6c56f6796f3 (diff)
Initial support for setting an error handler as well
-rw-r--r--include/call.h1
-rw-r--r--include/value.h1
-rw-r--r--zend/exception_handler.cpp25
3 files changed, 27 insertions, 0 deletions
diff --git a/include/call.h b/include/call.h
index f26fd29..80b3c74 100644
--- a/include/call.h
+++ b/include/call.h
@@ -47,6 +47,7 @@ inline PHPCPP_EXPORT Value require(const std::string &filename) { return requ
extern PHPCPP_EXPORT Value require_once(const char *filename);
inline PHPCPP_EXPORT Value require_once(const std::string &filename) { return require_once(filename.c_str()); }
extern PHPCPP_EXPORT Value set_exception_handler(const std::function<Value(Parameters &params)> &handler);
+extern PHPCPP_EXPORT Value set_error_handler(const std::function<Value(Parameters &params)> &handler);
extern PHPCPP_EXPORT const char *sapi_name();
/**
diff --git a/include/value.h b/include/value.h
index 5b746a1..bfd8e40 100644
--- a/include/value.h
+++ b/include/value.h
@@ -1215,6 +1215,7 @@ protected:
* Friend functions which have to access that zval directly
*/
friend Value set_exception_handler(const std::function<Value(Parameters &params)> &handler);
+ friend Value set_error_handler(const std::function<Value(Parameters &params)> &handler);
};
/**
diff --git a/zend/exception_handler.cpp b/zend/exception_handler.cpp
index 51874a4..75361b2 100644
--- a/zend/exception_handler.cpp
+++ b/zend/exception_handler.cpp
@@ -43,6 +43,31 @@ Value set_exception_handler(const std::function<Value(Parameters &params)> &hand
return output;
}
+Value set_error_handler(const std::function<Value(Parameters &params)> &handler)
+{
+ // create the functor which wraps our callback
+ Function functor(handler);
+
+ // initialize our output value
+ Value output;
+
+ // turn our user_error_handler into a Value if we have one, just so we can return it later on
+ if (EG(user_error_handler)) output = EG(user_error_handler);
+
+ // detach so we have the zval
+ auto value = functor.detach(true);
+
+ // alocate the user_error_handler
+ ALLOC_ZVAL(EG(user_error_handler));
+
+ // copy our zval into the user_error_handler
+ MAKE_COPY_ZVAL(&value, EG(user_error_handler));
+ EG(user_error_handler_error_reporting) = (int) (E_ALL | E_STRICT);
+
+ // return the original handler
+ return output;
+}
+
/**
* End of namespace
*/