php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch getDefaultValueConstantName.diff for Reflection related Bug #61602

Patch version 2012-04-03 00:23 UTC

Return to Bug #61602 | Download this patch
Patch Revisions:

Developer: pierrick@php.net

diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 1cf65ce..5b537f3 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -2568,6 +2568,74 @@ ZEND_METHOD(reflection_parameter, getDefaultValue)
 }
 /* }}} */
 
+ZEND_METHOD(reflection_parameter, defaultValueIsConstant)
+{
+	reflection_object *intern;
+	parameter_reference *param;
+	zend_op *precv;
+
+	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");
+		return;
+	}
+
+	*return_value = *precv->op2.zv;
+	INIT_PZVAL(return_value);
+	if (Z_TYPE_P(return_value) != IS_CONSTANT && Z_TYPE_P(return_value) != IS_CONSTANT_ARRAY) {
+		RETURN_FALSE;
+	}
+	RETURN_TRUE;
+}
+
+ZEND_METHOD(reflection_parameter, getDefaultValueConstantName)
+{
+	reflection_object *intern;
+	parameter_reference *param;
+	zend_op *precv;
+
+	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");
+		return;
+	}
+
+	*return_value = *precv->op2.zv;
+	INIT_PZVAL(return_value);
+	if (Z_TYPE_P(return_value) != IS_CONSTANT && Z_TYPE_P(return_value) != IS_CONSTANT_ARRAY) {
+		RETURN_FALSE;
+	}
+	RETURN_STRING(Z_STRVAL_P(return_value), 1);
+}
+
 /* {{{ 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 +5971,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, defaultValueIsConstant, arginfo_reflection__void, 0)
+	ZEND_ME(reflection_parameter, getDefaultValueConstantName, arginfo_reflection__void, 0)
 	PHP_FE_END
 };
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC