summaryrefslogtreecommitdiff
path: root/src/value.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-08 14:15:15 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-08 14:15:15 +0100
commit78e7865b8dac7229bdc128af870a4cad11cf1cd2 (patch)
treeff0a660ca7916e7c7d5e75d3f82a09033d514a39 /src/value.cpp
parent2c484adbab9255498953739cb4d9751353cc804d (diff)
exception is now thrown when a function is called that does not exist
Diffstat (limited to 'src/value.cpp')
-rw-r--r--src/value.cpp58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/value.cpp b/src/value.cpp
index b775892..7b1a931 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -1142,12 +1142,14 @@ Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Valu
}
/**
- * Call function with a number of parameters
- * @param argc Number of parameters
- * @param argv The parameters
+ * Helper function that runs the actual call
+ * @param object The object to call it on
+ * @param method The function or method to call
+ * @param args Number of arguments
+ * @param params The parameters
* @return Value
*/
-Value Value::exec(int argc, zval ***params) const
+static Value do_exec(zval **object, zval *method, int argc, zval ***params)
{
// the return zval
zval *retval = nullptr;
@@ -1156,13 +1158,35 @@ Value Value::exec(int argc, zval ***params) const
zval *oldException = EG(exception);
// call the function
- if (call_user_function_ex(CG(function_table), NULL, _val, &retval, argc, params, 1, NULL) != SUCCESS) return nullptr;
+ if (call_user_function_ex(CG(function_table), object, method, &retval, argc, params, 1, NULL) != SUCCESS)
+ {
+ // throw an exception, the function does not exist
+ throw Exception("Invalid call to "+Value(method).stringValue());
+
+ // unreachable, but let's return at least something to prevent compiler warnings
+ 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
+ if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception));
- // was an exception thrown? we throw a C++ new exception to give the C++ the chance to catch it
- if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception));
+ // no (additional) exception was thrown
+ return retval ? Value(retval) : nullptr;
+ }
+}
- // no (additional) exception was thrown
- return retval ? Value(retval) : nullptr;
+/**
+ * Call function with a number of parameters
+ * @param argc Number of parameters
+ * @param argv The parameters
+ * @return Value
+ */
+Value Value::exec(int argc, zval ***params) const
+{
+ // call helper function
+ return do_exec(nullptr, _val, argc, params);
}
/**
@@ -1177,20 +1201,8 @@ Value Value::exec(const char *name, int argc, struct _zval_struct ***params)
// wrap the name in a Php::Value object to get a zval
Value method(name);
- // the method to call and the return value
- zval *retval;
-
- // the current exception
- zval *oldException = EG(exception);
-
- // call the function
- if (call_user_function_ex(CG(function_table), &_val, method._val, &retval, argc, params, 1, NULL) != SUCCESS) return nullptr;
-
- // was an exception thrown?
- if (oldException != EG(exception)) throw OrigException(EG(exception));
-
- // no (additional) exception was thrown
- return retval ? Value(retval) : nullptr;
+ // call helper function
+ return do_exec(&_val, method._val, argc, params);
}
/**