From d8fe9239959dfeae11daa5de70126e30119d3b75 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 14 Jan 2015 09:46:43 +0100 Subject: 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 --- zend/eval.cpp | 53 +++-------------------------------------------------- 1 file changed, 3 insertions(+), 50 deletions(-) (limited to 'zend') 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(); } /** -- cgit v1.2.3