From 6ac0bc83b53ab854baaaba74dd54e60c562751ff Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 9 Apr 2014 17:07:51 +0200 Subject: generate warning when a function is called with not enough parameters --- zend/callable.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'zend') 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(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); + } } } -- cgit v1.2.3