/* Struct for parameters */
typedef struct _parameter_reference {
int offset;
+ int required;
struct _zend_arg_info *arg_info;
} parameter_reference;
/* }}} */
/* {{{ _parameter_string */
-static void _parameter_string(string *str, struct _zend_arg_info *arg_info, int offset, char* indent TSRMLS_DC)
+static void _parameter_string(string *str, struct _zend_arg_info *arg_info, int offset, int required, char* indent TSRMLS_DC)
{
string_printf(str, "Parameter #%d [ ", offset);
+ if (offset >= required) {
+ string_printf(str, "<optional> ");
+ } else {
+ string_printf(str, "<required> ");
+ }
if (arg_info->class_name) {
string_printf(str, "%s ", arg_info->class_name);
if (arg_info->allow_null) {
{
zend_uint i;
struct _zend_arg_info *arg_info = fptr->common.arg_info;
+ int required = fptr->common.required_num_args;
if (!arg_info) {
return;
string_printf(str, "%s- Parameters [%d] {\n", indent, fptr->common.num_args);
for (i = 0; i < fptr->common.num_args; i++) {
string_printf(str, "%s ", indent);
- _parameter_string(str, arg_info, i, indent TSRMLS_CC);
+ _parameter_string(str, arg_info, i, required, indent TSRMLS_CC);
string_write(str, "\n", sizeof("\n")-1);
arg_info++;
}
ref = (parameter_reference*) emalloc(sizeof(parameter_reference));
ref->arg_info = &arg_info[position];
ref->offset = position;
+ ref->required = fptr->common.required_num_args;
intern->ptr = ref;
intern->free_ptr = 1;
}
METHOD_NOTSTATIC_NUMPARAMS(0);
GET_REFLECTION_OBJECT_PTR(param);
string_init(&str);
- _parameter_string(&str, param->arg_info, param->offset, "" TSRMLS_CC);
+ _parameter_string(&str, param->arg_info, param->offset, param->required, "" TSRMLS_CC);
RETURN_STRINGL(str.string, str.len - 1, 0);
}
/* }}} */
}
/* }}} */
+/* {{{ proto public bool ReflectionParameter::isOptional()
+ Returns whether this parameter is an optional parameter */
+ZEND_METHOD(reflection_parameter, isOptional)
+{
+ reflection_object *intern;
+ parameter_reference *param;
+
+ METHOD_NOTSTATIC_NUMPARAMS(0);
+ GET_REFLECTION_OBJECT_PTR(param);
+
+ RETVAL_BOOL(param->offset >= param->required);
+}
+/* }}} */
+
/* {{{ 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)
ZEND_ME(reflection_parameter, isPassedByReference, NULL, 0)
ZEND_ME(reflection_parameter, getClass, NULL, 0)
ZEND_ME(reflection_parameter, allowsNull, NULL, 0)
+ ZEND_ME(reflection_parameter, isOptional, NULL, 0)
{NULL, NULL, NULL}
};
/* Struct for parameters */
typedef struct _parameter_reference {
int offset;
+ int required;
struct _zend_arg_info *arg_info;
} parameter_reference;
/* }}} */
/* {{{ _parameter_string */
-static void _parameter_string(string *str, struct _zend_arg_info *arg_info, int offset, char* indent TSRMLS_DC)
+static void _parameter_string(string *str, struct _zend_arg_info *arg_info, int offset, int required, char* indent TSRMLS_DC)
{
string_printf(str, "Parameter #%d [ ", offset);
+ if (offset >= required) {
+ string_printf(str, "<optional> ");
+ } else {
+ string_printf(str, "<required> ");
+ }
if (arg_info->class_name) {
string_printf(str, "%s ", arg_info->class_name);
if (arg_info->allow_null) {
{
zend_uint i;
struct _zend_arg_info *arg_info = fptr->common.arg_info;
+ int required = fptr->common.required_num_args;
if (!arg_info) {
return;
string_printf(str, "%s- Parameters [%d] {\n", indent, fptr->common.num_args);
for (i = 0; i < fptr->common.num_args; i++) {
string_printf(str, "%s ", indent);
- _parameter_string(str, arg_info, i, indent TSRMLS_CC);
+ _parameter_string(str, arg_info, i, required, indent TSRMLS_CC);
string_write(str, "\n", sizeof("\n")-1);
arg_info++;
}
ref = (parameter_reference*) emalloc(sizeof(parameter_reference));
ref->arg_info = &arg_info[position];
ref->offset = position;
+ ref->required = fptr->common.required_num_args;
intern->ptr = ref;
intern->free_ptr = 1;
}
METHOD_NOTSTATIC_NUMPARAMS(0);
GET_REFLECTION_OBJECT_PTR(param);
string_init(&str);
- _parameter_string(&str, param->arg_info, param->offset, "" TSRMLS_CC);
+ _parameter_string(&str, param->arg_info, param->offset, param->required, "" TSRMLS_CC);
RETURN_STRINGL(str.string, str.len - 1, 0);
}
/* }}} */
}
/* }}} */
+/* {{{ proto public bool ReflectionParameter::isOptional()
+ Returns whether this parameter is an optional parameter */
+ZEND_METHOD(reflection_parameter, isOptional)
+{
+ reflection_object *intern;
+ parameter_reference *param;
+
+ METHOD_NOTSTATIC_NUMPARAMS(0);
+ GET_REFLECTION_OBJECT_PTR(param);
+
+ RETVAL_BOOL(param->offset >= param->required);
+}
+/* }}} */
+
/* {{{ 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)
ZEND_ME(reflection_parameter, isPassedByReference, NULL, 0)
ZEND_ME(reflection_parameter, getClass, NULL, 0)
ZEND_ME(reflection_parameter, allowsNull, NULL, 0)
+ ZEND_ME(reflection_parameter, isOptional, NULL, 0)
{NULL, NULL, NULL}
};