summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-09 17:07:51 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-09 17:07:51 +0200
commit6ac0bc83b53ab854baaaba74dd54e60c562751ff (patch)
tree53f27649aa5960c4ffab6eda879571a49a70f8bc
parente11d3cdadc4619053f547c28cc6ff253c7378fd6 (diff)
generate warning when a function is called with not enough parameters
-rw-r--r--zend/callable.cpp49
1 files changed, 31 insertions, 18 deletions
diff --git a/zend/callable.cpp b/zend/callable.cpp
index caee311..a85ab72 100644
--- a/zend/callable.cpp
+++ b/zend/callable.cpp
@@ -31,27 +31,40 @@ void Callable::invoke(INTERNAL_FUNCTION_PARAMETERS)
// uncover the hidden pointer inside the function name
Callable *callable = HiddenPointer<Callable>(name);
- // construct parameters
- ParametersImpl params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
-
- // the function could throw an exception
- try
+ // check if sufficient parameters were passed (for some reason this check
+ // is not done by Zend, so we do it here ourselves)
+ if (ZEND_NUM_ARGS() < callable->_required)
{
- // get the result
- Value result(callable->invoke(params));
-
- // detach the zval (we don't want it to be destructed)
- zval *val = result.detach();
-
- // @todo php 5.6 has a RETVAL_ZVAL_FAST macro that can be used instead (and is faster)
-
- // return a full copy of the zval, and do not destruct it
- RETVAL_ZVAL(val, 1, 0);
+ // PHP itself only generates a warning when this happens, so we do the same too
+ Php::warning << name << "() expects at least " << callable->_required << " parameters, " << ZEND_NUM_ARGS() << " given" << std::flush;
+
+ // and we return null
+ RETURN_NULL();
}
- catch (Exception &exception)
+ else
{
- // process the exception
- process(exception TSRMLS_CC);
+ // construct parameters
+ ParametersImpl params(this_ptr, ZEND_NUM_ARGS() TSRMLS_CC);
+
+ // the function could throw an exception
+ try
+ {
+ // get the result
+ Value result(callable->invoke(params));
+
+ // detach the zval (we don't want it to be destructed)
+ zval *val = result.detach();
+
+ // @todo php 5.6 has a RETVAL_ZVAL_FAST macro that can be used instead (and is faster)
+
+ // return a full copy of the zval, and do not destruct it
+ RETVAL_ZVAL(val, 1, 0);
+ }
+ catch (Exception &exception)
+ {
+ // process the exception
+ process(exception TSRMLS_CC);
+ }
}
}