diff options
author | Ondřej Surý <ondrej@sury.org> | 2010-01-07 13:31:53 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2010-01-07 13:31:53 +0100 |
commit | 0fab6db7cac8d2be99579dd049f812a8ff98e74f (patch) | |
tree | 91f01b0d06916c78262404096bfd466b8e95e5b5 /ext/reflection/php_reflection.c | |
parent | d3a8757891280dc6650ca7eead67830c794b0e7b (diff) | |
download | php-0fab6db7cac8d2be99579dd049f812a8ff98e74f.tar.gz |
Imported Upstream version 5.3.1upstream/5.3.1
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r-- | ext/reflection/php_reflection.c | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index de1a2f08d..77af950df 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_reflection.c,v 1.164.2.33.2.45.2.58 2009/06/16 14:33:33 felipe Exp $ */ +/* $Id: php_reflection.c 287991 2009-09-03 14:02:51Z sebastian $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -533,23 +533,25 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in string_init(&dyn); count = 0; - zend_hash_internal_pointer_reset_ex(properties, &pos); + if (properties && zend_hash_num_elements(properties)) { + zend_hash_internal_pointer_reset_ex(properties, &pos); - while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) { - char *prop_name; - uint prop_name_size; - ulong index; + while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) { + char *prop_name; + uint prop_name_size; + ulong index; - if (zend_hash_get_current_key_ex(properties, &prop_name, &prop_name_size, &index, 1, &pos) == HASH_KEY_IS_STRING) { - if (prop_name_size && prop_name[0]) { /* skip all private and protected properties */ - if (!zend_hash_quick_exists(&ce->properties_info, prop_name, prop_name_size, zend_get_hash_value(prop_name, prop_name_size))) { - count++; - _property_string(&dyn, NULL, prop_name, sub_indent.string TSRMLS_CC); + if (zend_hash_get_current_key_ex(properties, &prop_name, &prop_name_size, &index, 1, &pos) == HASH_KEY_IS_STRING) { + if (prop_name_size && prop_name[0]) { /* skip all private and protected properties */ + if (!zend_hash_quick_exists(&ce->properties_info, prop_name, prop_name_size, zend_get_hash_value(prop_name, prop_name_size))) { + count++; + _property_string(&dyn, NULL, prop_name, sub_indent.string TSRMLS_CC); + } } + efree(prop_name); } - efree(prop_name); + zend_hash_move_forward_ex(properties, &pos); } - zend_hash_move_forward_ex(properties, &pos); } string_printf(str, "\n%s - Dynamic properties [%d] {\n", indent, count); @@ -1514,8 +1516,18 @@ ZEND_METHOD(reflection_function, __construct) fptr = (zend_function*)zend_get_closure_method_def(closure TSRMLS_CC); Z_ADDREF_P(closure); } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == SUCCESS) { + char *nsname; + lcname = zend_str_tolower_dup(name_str, name_len); - if (zend_hash_find(EG(function_table), lcname, name_len + 1, (void **)&fptr) == FAILURE) { + + /* Ignore leading "\" */ + nsname = lcname; + if (lcname[0] == '\\') { + nsname = &lcname[1]; + name_len--; + } + + if (zend_hash_find(EG(function_table), nsname, name_len + 1, (void **)&fptr) == FAILURE) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Function %s() does not exist", name_str); @@ -1717,7 +1729,7 @@ ZEND_METHOD(reflection_function, getStaticVariables) } /* }}} */ -/* {{{ proto public mixed ReflectionFunction::invoke(mixed* args) +/* {{{ proto public mixed ReflectionFunction::invoke([mixed* args]) Invokes the function */ ZEND_METHOD(reflection_function, invoke) { @@ -1732,7 +1744,7 @@ ZEND_METHOD(reflection_function, invoke) METHOD_NOTSTATIC(reflection_function_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶ms, &num_args) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) { return; } @@ -1754,7 +1766,9 @@ ZEND_METHOD(reflection_function, invoke) result = zend_call_function(&fci, &fcc TSRMLS_CC); - efree(params); + if (num_args) { + efree(params); + } if (result == FAILURE) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, @@ -2660,11 +2674,11 @@ ZEND_METHOD(reflection_method, invokeArgs) { if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Trying to invoke abstract method %s::%s", + "Trying to invoke abstract method %s::%s()", mptr->common.scope->name, mptr->common.function_name); } else { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Trying to invoke %s method %s::%s from scope %s", + "Trying to invoke %s method %s::%s() from scope %s", mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", mptr->common.scope->name, mptr->common.function_name, Z_OBJCE_P(getThis())->name); @@ -2691,7 +2705,7 @@ ZEND_METHOD(reflection_method, invokeArgs) if (!object) { efree(params); zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Trying to invoke non static method %s::%s without an object", + "Trying to invoke non static method %s::%s() without an object", mptr->common.scope->name, mptr->common.function_name); return; } @@ -3026,6 +3040,7 @@ ZEND_METHOD(reflection_class, getStaticProperties) if (zend_parse_parameters_none() == FAILURE) { return; } + GET_REFLECTION_OBJECT_PTR(ce); zend_update_class_constants(ce TSRMLS_CC); @@ -3041,12 +3056,20 @@ ZEND_METHOD(reflection_class, getStaticProperties) if (zend_hash_get_current_key_ex(CE_STATIC_MEMBERS(ce), &key, &key_len, &num_index, 0, &pos) != FAILURE && key) { char *prop_name, *class_name; + zval *prop_copy; zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name); - zval_add_ref(value); + /* filter privates from base classes */ + if (!(class_name && class_name[0] != '*' && strcmp(class_name, ce->name))) { + /* copy: enforce read only access */ + ALLOC_ZVAL(prop_copy); + *prop_copy = **value; + zval_copy_ctor(prop_copy); + INIT_PZVAL(prop_copy); - zend_hash_update(Z_ARRVAL_P(return_value), prop_name, strlen(prop_name)+1, value, sizeof(zval *), NULL); + add_assoc_zval(return_value, prop_name, prop_copy); + } } zend_hash_move_forward_ex(CE_STATIC_MEMBERS(ce), &pos); } @@ -5008,7 +5031,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_function___construct, 0) ZEND_ARG_INFO(0, name) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_reflection_function_invoke, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_function_invoke, 0, 0, 0) ZEND_ARG_INFO(0, args) ZEND_END_ARG_INFO() @@ -5442,7 +5465,7 @@ PHP_MINFO_FUNCTION(reflection) /* {{{ */ php_info_print_table_start(); php_info_print_table_header(2, "Reflection", "enabled"); - php_info_print_table_row(2, "Version", "$Revision: 1.164.2.33.2.45.2.58 $"); + php_info_print_table_row(2, "Version", "$Revision: 287991 $"); php_info_print_table_end(); } /* }}} */ @@ -5456,7 +5479,7 @@ zend_module_entry reflection_module_entry = { /* {{{ */ NULL, NULL, PHP_MINFO(reflection), - "$Revision: 1.164.2.33.2.45.2.58 $", + "$Revision: 287991 $", STANDARD_MODULE_PROPERTIES }; /* }}} */ |