diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-07-26 14:36:29 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-07-26 14:36:29 +0200 |
commit | 8801ed40905040115d8af6031c4f3c48d1f67e18 (patch) | |
tree | 5c6cc85186f2afd92be74ac4fcf5018446f5a870 /zend | |
parent | 513db71261813c2785e4292cfe05bc1d5b814f4f (diff) |
no more exceptions for wrong eval()'ed code
Diffstat (limited to 'zend')
-rw-r--r-- | zend/eval.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/zend/eval.cpp b/zend/eval.cpp index e0baaed..4632fff 100644 --- a/zend/eval.cpp +++ b/zend/eval.cpp @@ -33,16 +33,28 @@ Value eval(const std::string &phpCode) zval* retval = nullptr; if (zend_eval_stringl_ex((char *)phpCode.c_str(), (int32_t)phpCode.length(), retval, (char *)"", 1 TSRMLS_CC) != SUCCESS) { - // throw an exception, php couldn't evaluate code - throw Exception("PHP eval error"); - - // unreachable, but let's return at least something to prevent compiler warnings + // Do we want to throw an exception here? The original author + // did, but there are some reasons not to: + // + // 1. the PHP eval() function also does not throw exceptions. + // + // 2. the zend_eval_string() function already triggers a + // 'PHP parse error' when an error occurs, which also has + // to be handled. If we also throw an exception here, the + // user will have to write two error checks: for the error + // and the exception. + // + // if we _do_ want to throw an exception, we will first have to + // prevent the original zend_error to occur, and then turn it + // into an exception. An exception would be nicer from a C++ + // point of view, but because of the extra complexity, we do not + // this for now. return nullptr; } else { - // was an exception thrown inside the function? In that case we throw a C++ new exception - // to give the C++ code the chance to catch it + // was an exception thrown inside the eval()'ed code? In that case we + // throw a C++ new exception to give the C++ code the chance to catch it if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception) TSRMLS_CC); // no (additional) exception was thrown |