summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-14 09:46:43 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-14 09:46:43 +0100
commitd8fe9239959dfeae11daa5de70126e30119d3b75 (patch)
tree34cc008c32e26beb42f8fea1e1e45e2a1f960286
parente14d8c6f985aeaeb247387b51d6ec027655efb99 (diff)
fix for issue #159: the eval() function no longer relies on the Zend zend_eval_stringl_ex() function, because that function modifies the to-be-evaluated php code, which could result in syntax errors for perfectly valid PHP code
-rw-r--r--include/script.h6
-rw-r--r--zend/eval.cpp53
2 files changed, 9 insertions, 50 deletions
diff --git a/include/script.h b/include/script.h
index af68a59..fb546ea 100644
--- a/include/script.h
+++ b/include/script.h
@@ -65,6 +65,12 @@ public:
Script(const char *source) noexcept : Script("Unknown", source, ::strlen(source)) {}
/**
+ * Constructor based on a std::string
+ * @param source PHP source code to be evaluated
+ */
+ Script(const std::string &source) noexcept : Script("Unknown", source.c_str(), source.size()) {}
+
+ /**
* Destructor
*/
virtual ~Script();
diff --git a/zend/eval.cpp b/zend/eval.cpp
index 674d39d..c332898 100644
--- a/zend/eval.cpp
+++ b/zend/eval.cpp
@@ -23,55 +23,8 @@ namespace Php {
*/
Value eval(const std::string &phpCode)
{
- // we need the tsrm_ls variable
- TSRMLS_FETCH();
-
- // the current exception
- zval* oldException = EG(exception);
-
- // the return va
- zval *retval = nullptr;
- MAKE_STD_ZVAL(retval);
-
- // evaluate the string
- if (zend_eval_stringl_ex((char *)phpCode.c_str(), (int32_t)phpCode.length(), retval, (char *)"", 1 TSRMLS_CC) != SUCCESS)
- {
- // Do we want to throw an exception here? The original author of this code
- // 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 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);
-
- // wrap the return value in a value object
- Value result(retval);
-
- // the retval should now have two references: the value object and the
- // retval itselves, so we can remove one of it (the zval_ptr_dtor only
- // decrements refcount and won't destruct anything because there still
- // is one reference left inside the Value object)
- zval_ptr_dtor(&retval);
-
- // done
- return result;
- }
+ // we have a script for this
+ return Script(phpCode).execute();
}
/**
@@ -93,7 +46,7 @@ Value include(const std::string &filename)
Value include_once(const std::string &filename)
{
// we can simply execute a file
- return File(filename).execute();
+ return File(filename).once();
}
/**