diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-05-28 16:52:15 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-05-28 16:52:15 +0200 |
commit | 01c525f668ecff08bea21c4ff22745b8f77e8c3a (patch) | |
tree | 07ebb675549d7a8ceb905676e4894151122321ac /ext/reflection/php_reflection.c | |
parent | d4d61a2bcb9975c8aeddbc6603211064174087a9 (diff) | |
download | php-01c525f668ecff08bea21c4ff22745b8f77e8c3a.tar.gz |
Imported Upstream version 5.4.4~rc1upstream/5.4.4_rc1
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r-- | ext/reflection/php_reflection.c | 100 |
1 files changed, 84 insertions, 16 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 1cf65cee1..406da9382 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1457,6 +1457,49 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c } /* }}} */ +/* {{{ _reflection_param_get_default_param */ +static parameter_reference *_reflection_param_get_default_param(INTERNAL_FUNCTION_PARAMETERS) +{ + reflection_object *intern; + parameter_reference *param; + + GET_REFLECTION_OBJECT_PTR(param); + + if (param->fptr->type != ZEND_USER_FUNCTION) + { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot determine default value for internal functions"); + return NULL; + } + + if (param->offset < param->required) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Parameter is not optional"); + return NULL; + } + + return param; +} +/* }}} */ + +/* {{{ _reflection_param_get_default_precv */ +static zend_op *_reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAMETERS, parameter_reference *param) +{ + zend_op *precv; + + param = param ? param : _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU); + if (!param) { + return NULL; + } + + precv = _get_recv_op((zend_op_array*)param->fptr, param->offset); + if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) { + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Internal error"); + return NULL; + } + + return precv; +} +/* }}} */ + /* {{{ Preventing __clone from being called */ ZEND_METHOD(reflection, __clone) { @@ -2535,27 +2578,14 @@ ZEND_METHOD(reflection_parameter, isDefaultValueAvailable) Returns the default value of this parameter or throws an exception */ ZEND_METHOD(reflection_parameter, getDefaultValue) { - reflection_object *intern; - parameter_reference *param; - zend_op *precv; + parameter_reference *param = _reflection_param_get_default_param(INTERNAL_FUNCTION_PARAM_PASSTHRU); + zend_op *precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); if (zend_parse_parameters_none() == FAILURE) { return; } - GET_REFLECTION_OBJECT_PTR(param); - if (param->fptr->type != ZEND_USER_FUNCTION) - { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot determine default value for internal functions"); - return; - } - if (param->offset < param->required) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Parameter is not optional"); - return; - } - precv = _get_recv_op((zend_op_array*)param->fptr, param->offset); - if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Internal error"); + if (!(param && precv)) { return; } @@ -2568,6 +2598,42 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) } /* }}} */ +/* {{{ proto public bool ReflectionParameter::isDefaultValueConstant() + Returns whether the default value of this parameter is constant */ +ZEND_METHOD(reflection_parameter, isDefaultValueConstant) +{ + zend_op *precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL); + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { + RETURN_TRUE; + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto public mixed ReflectionParameter::getDefaultValueConstantName() + Returns the default value's constant name if default value is constant or false */ +ZEND_METHOD(reflection_parameter, getDefaultValueConstantName) +{ + zend_op *precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, NULL); + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { + RETURN_STRING(Z_STRVAL_P(precv->op2.zv), 1); + } + + RETURN_FALSE; +} +/* }}} */ + /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_method, export) @@ -5903,6 +5969,8 @@ static const zend_function_entry reflection_parameter_functions[] = { ZEND_ME(reflection_parameter, isOptional, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isDefaultValueAvailable, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getDefaultValue, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, isDefaultValueConstant, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, getDefaultValueConstantName, arginfo_reflection__void, 0) PHP_FE_END }; |