diff options
Diffstat (limited to 'zend/callable.cpp')
-rw-r--r-- | zend/callable.cpp | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/zend/callable.cpp b/zend/callable.cpp index 96f5f90..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); + } } } @@ -94,7 +107,7 @@ void Callable::initialize(zend_arg_info *info, const char *classname) const // because we do not support returning references in PHP-CPP, although Zend // engine allows it. Inside the name we hide a pointer to the current object finfo->_name = _ptr; - finfo->_name_len = strlen(_ptr); + finfo->_name_len = ::strlen(_ptr); finfo->_class_name = classname; // number of required arguments, and the expected return type |