diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f04bd020b770..a7c7d1ca8ebb 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -195,15 +195,13 @@ static zend_function *_copy_function(zend_function *fptr) /* {{{ */ if (fptr && (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { - zend_function *copy_fptr; - copy_fptr = emalloc(sizeof(zend_function)); + zend_function *copy_fptr = emalloc(sizeof(zend_function)); memcpy(copy_fptr, fptr, sizeof(zend_function)); copy_fptr->common.function_name = zend_string_copy(fptr->common.function_name); return copy_fptr; - } else { - /* no copy needed */ - return fptr; } + /* no copy needed */ + return fptr; } /* }}} */ @@ -236,37 +234,36 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */ if (intern->ptr) { switch (intern->ref_type) { - case REF_TYPE_PARAMETER: - reflection_free_parameter_reference(intern->ptr); - break; - case REF_TYPE_TYPE: - { - type_reference *type_ref = intern->ptr; - if (ZEND_TYPE_HAS_NAME(type_ref->type)) { - zend_string_release(ZEND_TYPE_NAME(type_ref->type)); + case REF_TYPE_PARAMETER: + reflection_free_parameter_reference(intern->ptr); + break; + case REF_TYPE_TYPE: { + type_reference *type_ref = intern->ptr; + if (ZEND_TYPE_HAS_NAME(type_ref->type)) { + zend_string_release(ZEND_TYPE_NAME(type_ref->type)); + } + efree(type_ref); + break; } - efree(type_ref); - break; - } - case REF_TYPE_FUNCTION: - _free_function(intern->ptr); - break; - case REF_TYPE_PROPERTY: - reflection_free_property_reference(intern->ptr); - break; - case REF_TYPE_ATTRIBUTE: { - attribute_reference *attr_ref = intern->ptr; - if (attr_ref->filename) { - zend_string_release(attr_ref->filename); + case REF_TYPE_FUNCTION: + _free_function(intern->ptr); + break; + case REF_TYPE_PROPERTY: + reflection_free_property_reference(intern->ptr); + break; + case REF_TYPE_ATTRIBUTE: { + attribute_reference *attr_ref = intern->ptr; + if (attr_ref->filename) { + zend_string_release(attr_ref->filename); + } + efree(intern->ptr); + break; } - efree(intern->ptr); - break; - } - case REF_TYPE_GENERATOR: - case REF_TYPE_FIBER: - case REF_TYPE_CLASS_CONSTANT: - case REF_TYPE_OTHER: - break; + case REF_TYPE_GENERATOR: + case REF_TYPE_FIBER: + case REF_TYPE_CLASS_CONSTANT: + case REF_TYPE_OTHER: + break; } } intern->ptr = NULL; @@ -306,9 +303,6 @@ static void _zend_extension_string(smart_str *str, const zend_extension *extensi /* {{{ _class_string */ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const char *indent) { - int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0; - zend_string *sub_indent = strpprintf(0, "%s ", indent); - /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */ if (ce->doc_comment) { smart_str_append_printf(str, "%s%s", indent, ZSTR_VAL(ce->doc_comment)); @@ -366,15 +360,13 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const ); } if (ce->num_interfaces) { - uint32_t i; - ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED); if (ce->ce_flags & ZEND_ACC_INTERFACE) { smart_str_append_printf(str, " extends %s", ZSTR_VAL(ce->interfaces[0]->name)); } else { smart_str_append_printf(str, " implements %s", ZSTR_VAL(ce->interfaces[0]->name)); } - for (i = 1; i < ce->num_interfaces; ++i) { + for (uint32_t i = 1; i < ce->num_interfaces; ++i) { smart_str_append_printf(str, ", %s", ZSTR_VAL(ce->interfaces[i]->name)); } } @@ -386,6 +378,8 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const ce->info.user.line_start, ce->info.user.line_end); } + zend_string *sub_indent = strpprintf(0, "%s ", indent); + /* Constants */ uint32_t total_count = zend_hash_num_elements(&ce->constants_table); uint32_t constant_count = 0; @@ -396,10 +390,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const * times (count the constants vs. enum cases, print the constants, print * the enum cases) use some temporary helper smart strings. */ if (total_count > 0) { - zend_string *key; - zend_class_constant *c; - - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), key, c) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), zend_string *key, zend_class_constant *c) { if (ZEND_CLASS_CONST_FLAGS(c) & ZEND_CLASS_CONST_IS_CASE) { _enum_case_string(&enum_case_str, key, c, ZSTR_VAL(sub_indent)); enum_case_count++; @@ -432,11 +423,11 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const /* Static properties */ /* counting static properties */ - count = zend_hash_num_elements(&ce->properties_info); + int count = zend_hash_num_elements(&ce->properties_info); + int count_static_props = 0; + int count_shadow_props = 0; if (count > 0) { - zend_property_info *prop; - - ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) { if ((prop->flags & ZEND_ACC_PRIVATE) && prop->ce != ce) { count_shadow_props++; } else if (prop->flags & ZEND_ACC_STATIC) { @@ -448,9 +439,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const /* static properties */ smart_str_append_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props); if (count_static_props > 0) { - zend_property_info *prop; - - ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) { if ((prop->flags & ZEND_ACC_STATIC) && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) { _property_string(str, prop, NULL, ZSTR_VAL(sub_indent)); } @@ -461,10 +450,9 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const /* Static methods */ /* counting static methods */ count = zend_hash_num_elements(&ce->function_table); + int count_static_funcs = 0; if (count > 0) { - zend_function *mptr; - - ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -476,9 +464,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const /* static methods */ smart_str_append_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs); if (count_static_funcs > 0) { - zend_function *mptr; - - ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -495,11 +481,10 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; smart_str_append_printf(str, "\n%s - Properties [%d] {\n", indent, count); if (count > 0) { - zend_property_info *prop; - - ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) { if (!(prop->flags & ZEND_ACC_STATIC) - && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) { + && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce) + ) { _property_string(str, prop, NULL, ZSTR_VAL(sub_indent)); } } ZEND_HASH_FOREACH_END(); @@ -508,12 +493,11 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const if (obj && Z_TYPE_P(obj) == IS_OBJECT) { HashTable *properties = zend_get_properties_no_lazy_init(Z_OBJ_P(obj)); - zend_string *prop_name; smart_str prop_str = {0}; count = 0; if (properties && zend_hash_num_elements(properties)) { - ZEND_HASH_FOREACH_STR_KEY(properties, prop_name) { + ZEND_HASH_FOREACH_STR_KEY(properties, zend_string *prop_name) { if (prop_name && ZSTR_LEN(prop_name) && ZSTR_VAL(prop_name)[0]) { /* skip all private and protected properties */ if (!zend_hash_exists(&ce->properties_info, prop_name)) { count++; @@ -532,11 +516,10 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const /* Non static methods */ count = zend_hash_num_elements(&ce->function_table) - count_static_funcs; if (count > 0) { - zend_function *mptr; smart_str method_str = {0}; count = 0; - ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) { if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) { @@ -574,7 +557,6 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const /* {{{ _const_string */ static void _const_string(smart_str *str, const char *name, zval *value, const char *indent) { - const char *type = zend_zval_type_name(value); uint32_t flags = Z_CONSTANT_FLAGS_P(value); smart_str_appends(str, indent); @@ -600,6 +582,7 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c smart_str_appends(str, "> "); } + const char *type = zend_zval_type_name(value); smart_str_appends(str, type); smart_str_appendc(str, ' '); smart_str_appends(str, name); @@ -627,14 +610,14 @@ static void _class_const_string(smart_str *str, const zend_string *name, zend_cl return; } + if (c->doc_comment) { + smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(c->doc_comment)); + } const char *visibility = zend_visibility_string(ZEND_CLASS_CONST_FLAGS(c)); const char *final = ZEND_CLASS_CONST_FLAGS(c) & ZEND_ACC_FINAL ? "final " : ""; zend_string *type_str = ZEND_TYPE_IS_SET(c->type) ? zend_type_to_string(c->type) : NULL; const char *type = type_str ? ZSTR_VAL(type_str) : zend_zval_type_name(&c->value); - if (c->doc_comment) { - smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(c->doc_comment)); - } smart_str_append_printf(str, "%sConstant [ %s%s %s %s ] { ", indent, final, visibility, type, ZSTR_VAL(name)); if (Z_TYPE(c->value) == IS_ARRAY) { @@ -689,7 +672,7 @@ static zend_op *get_recv_op(const zend_op_array *op_array, uint32_t offset) ++offset; while (op < end) { if ((op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT - || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == offset) + || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == offset) { return op; } @@ -712,13 +695,10 @@ static void format_default_value(smart_str *str, const zval *value) { if (smart_str_append_zval(str, value, SIZE_MAX) == SUCCESS) { /* Nothing to do. */ } else if (Z_TYPE_P(value) == IS_ARRAY) { - zend_string *str_key; - zend_long num_key; - zval *zv; bool is_list = zend_array_is_list(Z_ARRVAL_P(value)); bool first = true; smart_str_appendc(str, '['); - ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(value), num_key, str_key, zv) { + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(value), zend_long num_key, zend_string *str_key, zval *zv) { if (!first) { smart_str_appends(str, ", "); } @@ -756,7 +736,7 @@ static void format_default_value(smart_str *str, const zval *value) { } /* {{{ _parameter_string */ -static void _parameter_string(smart_str *str, const zend_function *fptr, const struct _zend_arg_info *arg_info, uint32_t offset, bool required, char* indent) +static void _parameter_string(smart_str *str, const zend_function *fptr, const struct _zend_arg_info *arg_info, uint32_t offset, bool required) { smart_str_append_printf(str, "Parameter #%d [ ", offset); if (!required) { @@ -804,21 +784,21 @@ static void _parameter_string(smart_str *str, const zend_function *fptr, const s static void _function_parameter_string(smart_str *str, const zend_function *fptr, char* indent) { struct _zend_arg_info *arg_info = fptr->common.arg_info; - uint32_t i, num_args, num_required = fptr->common.required_num_args; - if (!arg_info) { return; } - num_args = fptr->common.num_args; + uint32_t num_args = fptr->common.num_args; if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } + uint32_t num_required = fptr->common.required_num_args; + smart_str_appendc(str, '\n'); smart_str_append_printf(str, "%s- Parameters [%d] {\n", indent, num_args); - for (i = 0; i < num_args; i++) { + for (uint32_t i = 0; i < num_args; i++) { smart_str_append_printf(str, "%s ", indent); - _parameter_string(str, fptr, arg_info, i, i < num_required, indent); + _parameter_string(str, fptr, arg_info, i, i < num_required); smart_str_appendc(str, '\n'); arg_info++; } @@ -829,16 +809,12 @@ static void _function_parameter_string(smart_str *str, const zend_function *fptr /* {{{ _function_closure_string */ static void _function_closure_string(smart_str *str, const zend_function *fptr, const char* indent) { - uint32_t i, count; - const zend_string *key; - const HashTable *static_variables; - if (fptr->type != ZEND_USER_FUNCTION || !fptr->op_array.static_variables) { return; } - static_variables = ZEND_MAP_PTR_GET(fptr->op_array.static_variables_ptr); - count = zend_hash_num_elements(static_variables); + const HashTable *static_variables = ZEND_MAP_PTR_GET(fptr->op_array.static_variables_ptr); + uint32_t count = zend_hash_num_elements(static_variables); if (!count) { return; @@ -846,8 +822,8 @@ static void _function_closure_string(smart_str *str, const zend_function *fptr, smart_str_appendc(str, '\n'); smart_str_append_printf(str, "%s- Bound Variables [%u] {\n", indent, count); - i = 0; - ZEND_HASH_MAP_FOREACH_STR_KEY(static_variables, key) { + uint32_t i = 0; + ZEND_HASH_MAP_FOREACH_STR_KEY(static_variables, const zend_string *key) { smart_str_append_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key)); } ZEND_HASH_FOREACH_END(); smart_str_append_printf(str, "%s}\n", indent); @@ -857,9 +833,6 @@ static void _function_closure_string(smart_str *str, const zend_function *fptr, /* {{{ _function_string */ static void _function_string(smart_str *str, const zend_function *fptr, const zend_class_entry *scope, const char* indent) { - smart_str param_indent = {0}; - zend_function *overwrites; - /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) * What's "wrong" is that any whitespace before the doc comment start is * swallowed, leading to an unaligned comment. @@ -884,10 +857,15 @@ static void _function_string(smart_str *str, const zend_function *fptr, const ze if (fptr->common.scope != scope) { smart_str_append_printf(str, ", inherits %s", ZSTR_VAL(fptr->common.scope->name)); } else if (fptr->common.scope->parent) { - if ((overwrites = zend_hash_find_ptr_lc(&fptr->common.scope->parent->function_table, fptr->common.function_name)) != NULL) { - if (fptr->common.scope != overwrites->common.scope && !(overwrites->common.fn_flags & ZEND_ACC_PRIVATE)) { - smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); - } + zend_function *overwrites = zend_hash_find_ptr_lc( + &fptr->common.scope->parent->function_table, + fptr->common.function_name + ); + if (overwrites != NULL + && fptr->common.scope != overwrites->common.scope + && !(overwrites->common.fn_flags & ZEND_ACC_PRIVATE) + ) { + smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); } } } @@ -941,6 +919,7 @@ static void _function_string(smart_str *str, const zend_function *fptr, const ze fptr->op_array.line_start, fptr->op_array.line_end); } + smart_str param_indent = {0}; smart_str_append_printf(¶m_indent, "%s ", indent); smart_str_0(¶m_indent); if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) { @@ -967,98 +946,99 @@ static zval *property_get_default(const zend_property_info *prop_info) { zval *prop = &ce->default_static_members_table[prop_info->offset]; ZVAL_DEINDIRECT(prop); return prop; - } else if (prop_info->flags & ZEND_ACC_VIRTUAL) { + } + if (prop_info->flags & ZEND_ACC_VIRTUAL) { return NULL; - } else { - return &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)]; } + return &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)]; } /* {{{ _property_string */ static void _property_string(smart_str *str, const zend_property_info *prop, const char *prop_name, const char* indent) { - if (prop && prop->doc_comment) { + if (!prop) { + // Dynamic property, known to have no doc comment, flags, etc. + smart_str_append_printf(str, "%sProperty [ public $%s ]\n", indent, prop_name); + return; + } + if (prop->doc_comment) { smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(prop->doc_comment)); } smart_str_append_printf(str, "%sProperty [ ", indent); - if (!prop) { - smart_str_append_printf(str, " public $%s", prop_name); - } else { - if (prop->flags & ZEND_ACC_ABSTRACT) { - smart_str_appends(str, "abstract "); - } - if (prop->flags & ZEND_ACC_FINAL) { - smart_str_appends(str, "final "); - } - /* These are mutually exclusive */ - switch (prop->flags & ZEND_ACC_PPP_MASK) { - case ZEND_ACC_PUBLIC: - smart_str_appends(str, "public "); - break; - case ZEND_ACC_PRIVATE: - smart_str_appends(str, "private "); - break; - case ZEND_ACC_PROTECTED: - smart_str_appends(str, "protected "); - break; - } - switch (prop->flags & ZEND_ACC_PPP_SET_MASK) { - case ZEND_ACC_PRIVATE_SET: - smart_str_appends(str, "private(set) "); - break; - case ZEND_ACC_PROTECTED_SET: - smart_str_appends(str, "protected(set) "); - break; - case ZEND_ACC_PUBLIC_SET: - ZEND_UNREACHABLE(); - break; - } - if (prop->flags & ZEND_ACC_STATIC) { - smart_str_appends(str, "static "); - } - if (prop->flags & ZEND_ACC_READONLY) { - smart_str_appends(str, "readonly "); - } - if (prop->flags & ZEND_ACC_VIRTUAL) { - smart_str_appends(str, "virtual "); - } - if (ZEND_TYPE_IS_SET(prop->type)) { - zend_string *type_str = zend_type_to_string(prop->type); - smart_str_append(str, type_str); - smart_str_appendc(str, ' '); - zend_string_release(type_str); - } - if (!prop_name) { - const char *class_name; - zend_unmangle_property_name(prop->name, &class_name, &prop_name); - } - smart_str_append_printf(str, "$%s", prop_name); + if (prop->flags & ZEND_ACC_ABSTRACT) { + smart_str_appends(str, "abstract "); + } + if (prop->flags & ZEND_ACC_FINAL) { + smart_str_appends(str, "final "); + } + /* These are mutually exclusive */ + switch (prop->flags & ZEND_ACC_PPP_MASK) { + case ZEND_ACC_PUBLIC: + smart_str_appends(str, "public "); + break; + case ZEND_ACC_PRIVATE: + smart_str_appends(str, "private "); + break; + case ZEND_ACC_PROTECTED: + smart_str_appends(str, "protected "); + break; + } + switch (prop->flags & ZEND_ACC_PPP_SET_MASK) { + case ZEND_ACC_PRIVATE_SET: + smart_str_appends(str, "private(set) "); + break; + case ZEND_ACC_PROTECTED_SET: + smart_str_appends(str, "protected(set) "); + break; + case ZEND_ACC_PUBLIC_SET: + ZEND_UNREACHABLE(); + break; + } + if (prop->flags & ZEND_ACC_STATIC) { + smart_str_appends(str, "static "); + } + if (prop->flags & ZEND_ACC_READONLY) { + smart_str_appends(str, "readonly "); + } + if (prop->flags & ZEND_ACC_VIRTUAL) { + smart_str_appends(str, "virtual "); + } + if (ZEND_TYPE_IS_SET(prop->type)) { + zend_string *type_str = zend_type_to_string(prop->type); + smart_str_append(str, type_str); + smart_str_appendc(str, ' '); + zend_string_release(type_str); + } + if (!prop_name) { + const char *class_name; + zend_unmangle_property_name(prop->name, &class_name, &prop_name); + } + smart_str_append_printf(str, "$%s", prop_name); - const zval *default_value = property_get_default(prop); - if (default_value && !Z_ISUNDEF_P(default_value)) { - smart_str_appends(str, " = "); - format_default_value(str, default_value); - } - if (prop->hooks != NULL) { - smart_str_appends(str, " {"); - const zend_function *get_hooked = prop->hooks[ZEND_PROPERTY_HOOK_GET]; - if (get_hooked != NULL) { - if (get_hooked->common.fn_flags & ZEND_ACC_FINAL) { - smart_str_appends(str, " final get;"); - } else { - smart_str_appends(str, " get;"); - } + const zval *default_value = property_get_default(prop); + if (default_value && !Z_ISUNDEF_P(default_value)) { + smart_str_appends(str, " = "); + format_default_value(str, default_value); + } + if (prop->hooks != NULL) { + smart_str_appends(str, " {"); + const zend_function *get_hooked = prop->hooks[ZEND_PROPERTY_HOOK_GET]; + if (get_hooked != NULL) { + if (get_hooked->common.fn_flags & ZEND_ACC_FINAL) { + smart_str_appends(str, " final get;"); + } else { + smart_str_appends(str, " get;"); } - const zend_function *set_hooked = prop->hooks[ZEND_PROPERTY_HOOK_SET]; - if (set_hooked != NULL) { - if (set_hooked->common.fn_flags & ZEND_ACC_FINAL) { - smart_str_appends(str, " final set;"); - } else { - smart_str_appends(str, " set;"); - } + } + const zend_function *set_hooked = prop->hooks[ZEND_PROPERTY_HOOK_SET]; + if (set_hooked != NULL) { + if (set_hooked->common.fn_flags & ZEND_ACC_FINAL) { + smart_str_appends(str, " final set;"); + } else { + smart_str_appends(str, " set;"); } - smart_str_appends(str, " }"); } + smart_str_appends(str, " }"); } smart_str_appends(str, " ]\n"); @@ -1067,45 +1047,47 @@ static void _property_string(smart_str *str, const zend_property_info *prop, con static void _extension_ini_string(const zend_ini_entry *ini_entry, smart_str *str, int number) /* {{{ */ { - char *comma = ""; - - if (number == ini_entry->module_number) { - smart_str_append_printf(str, " Entry [ %s <", ZSTR_VAL(ini_entry->name)); - if (ini_entry->modifiable == ZEND_INI_ALL) { - smart_str_appends(str, "ALL"); - } else { - if (ini_entry->modifiable & ZEND_INI_USER) { - smart_str_appends(str, "USER"); - comma = ","; - } - if (ini_entry->modifiable & ZEND_INI_PERDIR) { - smart_str_append_printf(str, "%sPERDIR", comma); - comma = ","; - } - if (ini_entry->modifiable & ZEND_INI_SYSTEM) { - smart_str_append_printf(str, "%sSYSTEM", comma); - } + if (number != ini_entry->module_number) { + return; + } + smart_str_append_printf(str, " Entry [ %s <", ZSTR_VAL(ini_entry->name)); + if (ini_entry->modifiable == ZEND_INI_ALL) { + smart_str_appends(str, "ALL"); + } else { + char *comma = ""; + if (ini_entry->modifiable & ZEND_INI_USER) { + smart_str_appends(str, "USER"); + comma = ","; } - - smart_str_appends(str, "> ]\n"); - smart_str_append_printf(str, " Current = '%s'\n", ini_entry->value ? ZSTR_VAL(ini_entry->value) : ""); - if (ini_entry->modified) { - smart_str_append_printf(str, " Default = '%s'\n", ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : ""); + if (ini_entry->modifiable & ZEND_INI_PERDIR) { + smart_str_append_printf(str, "%sPERDIR", comma); + comma = ","; } - smart_str_appends(str, " }\n"); + if (ini_entry->modifiable & ZEND_INI_SYSTEM) { + smart_str_append_printf(str, "%sSYSTEM", comma); + } + } + + smart_str_appends(str, "> ]\n"); + smart_str_append_printf(str, " Current = '%s'\n", ini_entry->value ? ZSTR_VAL(ini_entry->value) : ""); + if (ini_entry->modified) { + smart_str_append_printf(str, " Default = '%s'\n", ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : ""); } + smart_str_appends(str, " }\n"); } /* }}} */ static void _extension_class_string(zend_class_entry *ce, zend_string *key, smart_str *str, const char *indent, const zend_module_entry *module, int *num_classes) /* {{{ */ { - if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) { + if (ce->type == ZEND_INTERNAL_CLASS + && ce->info.internal.module + && !strcasecmp(ce->info.internal.module->name, module->name) /* dump class if it is not an alias */ - if (zend_string_equals_ci(ce->name, key)) { - smart_str_appendc(str, '\n'); - _class_string(str, ce, NULL, indent); - (*num_classes)++; - } + && zend_string_equals_ci(ce->name, key) + ) { + smart_str_appendc(str, '\n'); + _class_string(str, ce, NULL, indent); + (*num_classes)++; } } /* }}} */ @@ -1132,18 +1114,18 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) / smart_str_append_printf(str, " Dependency [ %s (", dep->name); switch(dep->type) { - case MODULE_DEP_REQUIRED: - smart_str_appends(str, "Required"); - break; - case MODULE_DEP_CONFLICTS: - smart_str_appends(str, "Conflicts"); - break; - case MODULE_DEP_OPTIONAL: - smart_str_appends(str, "Optional"); - break; - default: - smart_str_appends(str, "Error"); /* shouldn't happen */ - break; + case MODULE_DEP_REQUIRED: + smart_str_appends(str, "Required"); + break; + case MODULE_DEP_CONFLICTS: + smart_str_appends(str, "Conflicts"); + break; + case MODULE_DEP_OPTIONAL: + smart_str_appends(str, "Optional"); + break; + default: + smart_str_appends(str, "Error"); /* shouldn't happen */ + break; } if (dep->rel) { @@ -1160,8 +1142,7 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) / { smart_str str_ini = {0}; - zend_ini_entry *ini_entry; - ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), ini_entry) { + ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), zend_ini_entry *ini_entry) { _extension_ini_string(ini_entry, &str_ini, module->module_number); } ZEND_HASH_FOREACH_END(); if (smart_str_get_len(&str_ini) > 0) { @@ -1174,10 +1155,9 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) / { smart_str str_constants = {0}; - zend_constant *constant; int num_constants = 0; - ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), zend_constant *constant) { if (ZEND_CONSTANT_MODULE_NUMBER(constant) == module->module_number) { _const_string(&str_constants, ZSTR_VAL(constant->name), &constant->value, " "); num_constants++; @@ -1193,12 +1173,12 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) / } { - zend_function *fptr; bool first = true; - ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), fptr) { + ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), zend_function *fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION - && fptr->internal_function.module == module) { + && fptr->internal_function.module == module + ) { if (first) { smart_str_appends(str, "\n - Functions {\n"); first = false; @@ -1213,11 +1193,9 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) / { smart_str str_classes = {0}; - zend_string *key; - zend_class_entry *ce; int num_classes = 0; - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), zend_string *key, zend_class_entry *ce) { _extension_class_string(ce, key, &str_classes, " ", module, &num_classes); } ZEND_HASH_FOREACH_END(); if (num_classes) { @@ -1236,12 +1214,9 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) / static void reflection_attribute_factory(zval *object, HashTable *attributes, zend_attribute *data, zend_class_entry *scope, uint32_t target, zend_string *filename) { - reflection_object *intern; - attribute_reference *reference; - object_init_ex(object, reflection_attribute_ptr); - intern = Z_REFLECTION_P(object); - reference = (attribute_reference*) emalloc(sizeof(attribute_reference)); + reflection_object *intern = Z_REFLECTION_P(object); + attribute_reference *reference = (attribute_reference*) emalloc(sizeof(attribute_reference)); reference->attributes = attributes; reference->data = data; reference->scope = scope; @@ -1257,15 +1232,13 @@ static zend_result read_attributes(zval *ret, HashTable *attributes, zend_class_ uint32_t offset, uint32_t target, zend_string *name, const zend_class_entry *base, zend_string *filename) /* {{{ */ { ZEND_ASSERT(attributes != NULL); - - zend_attribute *attr; zval tmp; if (name) { // Name based filtering using lowercased key. zend_string *filter = zend_string_tolower(name); - ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, zend_attribute *attr) { if (attr->offset == offset && zend_string_equals(attr->lcname, filter)) { reflection_attribute_factory(&tmp, attributes, attr, scope, target, filename); add_next_index_zval(ret, &tmp); @@ -1276,7 +1249,7 @@ static zend_result read_attributes(zval *ret, HashTable *attributes, zend_class_ return SUCCESS; } - ZEND_HASH_PACKED_FOREACH_PTR(attributes, attr) { + ZEND_HASH_PACKED_FOREACH_PTR(attributes, zend_attribute *attr) { if (attr->offset != offset) { continue; } @@ -1383,12 +1356,10 @@ static void _function_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /* {{{ zend_reflection_class_factory */ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object) { - reflection_object *intern; - zend_class_entry *reflection_ce = ce->ce_flags & ZEND_ACC_ENUM ? reflection_enum_ptr : reflection_class_ptr; object_init_ex(object, reflection_ce); - intern = Z_REFLECTION_P(object); + reflection_object *intern = Z_REFLECTION_P(object); intern->ptr = ce; intern->ref_type = REF_TYPE_OTHER; intern->ce = ce; @@ -1411,13 +1382,9 @@ static void reflection_extension_factory(zval *object, zend_module_entry *module /* {{{ reflection_parameter_factory */ static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, uint32_t offset, bool required, zval *object) { - reflection_object *intern; - parameter_reference *reference; - zval *prop_name; - object_init_ex(object, reflection_parameter_ptr); - intern = Z_REFLECTION_P(object); - reference = (parameter_reference*) emalloc(sizeof(parameter_reference)); + reflection_object *intern = Z_REFLECTION_P(object); + parameter_reference *reference = (parameter_reference*) emalloc(sizeof(parameter_reference)); reference->arg_info = arg_info; reference->offset = offset; reference->required = required; @@ -1429,7 +1396,7 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje ZVAL_OBJ_COPY(&intern->obj, Z_OBJ_P(closure_object)); } - prop_name = reflection_prop_name(object); + zval *prop_name = reflection_prop_name(object); ZVAL_STR_COPY(prop_name, arg_info->name); } /* }}} */ @@ -1478,8 +1445,6 @@ static reflection_type_kind get_type_kind(zend_type type) { /* {{{ reflection_type_factory */ static void reflection_type_factory(zend_type type, zval *object, bool legacy_behavior) { - reflection_object *intern; - type_reference *reference; reflection_type_kind type_kind = get_type_kind(type); bool is_mixed = ZEND_TYPE_PURE_MASK(type) == MAY_BE_ANY; bool is_only_null = (ZEND_TYPE_PURE_MASK(type) == MAY_BE_NULL && !ZEND_TYPE_IS_COMPLEX(type)); @@ -1497,8 +1462,8 @@ static void reflection_type_factory(zend_type type, zval *object, bool legacy_be default: ZEND_UNREACHABLE(); } - intern = Z_REFLECTION_P(object); - reference = (type_reference*) emalloc(sizeof(type_reference)); + reflection_object *intern = Z_REFLECTION_P(object); + type_reference *reference = (type_reference*) emalloc(sizeof(type_reference)); reference->type = type; reference->legacy_behavior = legacy_behavior && type_kind == NAMED_TYPE && !is_mixed && !is_only_null; intern->ptr = reference; @@ -1518,9 +1483,8 @@ static void reflection_type_factory(zend_type type, zval *object, bool legacy_be /* {{{ reflection_function_factory */ static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object) { - reflection_object *intern; object_init_ex(object, reflection_function_ptr); - intern = Z_REFLECTION_P(object); + reflection_object *intern = Z_REFLECTION_P(object); intern->ptr = function; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = NULL; @@ -1534,10 +1498,8 @@ static void reflection_function_factory(zend_function *function, zval *closure_o /* {{{ reflection_method_factory */ static void reflection_method_factory(zend_class_entry *ce, zend_function *method, zval *closure_object, zval *object) { - reflection_object *intern; - object_init_ex(object, reflection_method_ptr); - intern = Z_REFLECTION_P(object); + reflection_object *intern = Z_REFLECTION_P(object); intern->ptr = method; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; @@ -1553,12 +1515,9 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho /* {{{ reflection_property_factory */ static void reflection_property_factory(zend_class_entry *ce, zend_string *name, zend_property_info *prop, zval *object) { - reflection_object *intern; - property_reference *reference; - object_init_ex(object, reflection_property_ptr); - intern = Z_REFLECTION_P(object); - reference = (property_reference*) emalloc(sizeof(property_reference)); + reflection_object *intern = Z_REFLECTION_P(object); + property_reference *reference = (property_reference*) emalloc(sizeof(property_reference)); reference->prop = prop; reference->unmangled_name = zend_string_copy(name); memset(reference->cache_slot, 0, sizeof(reference->cache_slot)); @@ -1580,10 +1539,8 @@ static void reflection_property_factory_str(zend_class_entry *ce, const char *na /* {{{ reflection_class_constant_factory */ static void reflection_class_constant_factory(zend_string *name_str, zend_class_constant *constant, zval *object) { - reflection_object *intern; - object_init_ex(object, reflection_class_constant_ptr); - intern = Z_REFLECTION_P(object); + reflection_object *intern = Z_REFLECTION_P(object); intern->ptr = constant; intern->ref_type = REF_TYPE_CLASS_CONSTANT; intern->ce = constant->ce; @@ -1595,13 +1552,11 @@ static void reflection_class_constant_factory(zend_string *name_str, zend_class_ static void reflection_enum_case_factory(const zend_class_entry *ce, zend_string *name_str, zend_class_constant *constant, zval *object) { - reflection_object *intern; - zend_class_entry *case_reflection_class = ce->enum_backing_type == IS_UNDEF ? reflection_enum_unit_case_ptr : reflection_enum_backed_case_ptr; object_init_ex(object, case_reflection_class); - intern = Z_REFLECTION_P(object); + reflection_object *intern = Z_REFLECTION_P(object); intern->ptr = constant; intern->ref_type = REF_TYPE_CLASS_CONSTANT; intern->ce = constant->ce; @@ -1617,15 +1572,14 @@ static zend_result get_parameter_default(zval *result, const parameter_reference return FAILURE; } return zend_get_default_from_internal_arg_info(result, param->arg_info); - } else { - zval *default_value = get_default_from_recv((const zend_op_array *) param->fptr, param->offset); - if (!default_value) { - return FAILURE; - } - - ZVAL_COPY(result, default_value); - return SUCCESS; } + zval *default_value = get_default_from_recv((const zend_op_array *) param->fptr, param->offset); + if (!default_value) { + return FAILURE; + } + + ZVAL_COPY(result, default_value); + return SUCCESS; } /* {{{ Preventing __clone from being called */ @@ -1692,14 +1646,12 @@ ZEND_METHOD(Reflection, getModifierNames) /* {{{ Constructor. Throws an Exception in case the given function does not exist */ ZEND_METHOD(ReflectionFunction, __construct) { - zval *object; zend_object *closure_obj = NULL; - reflection_object *intern; zend_function *fptr; zend_string *fname, *lcname; - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJ_OF_CLASS_OR_STR(closure_obj, zend_ce_closure, fname) @@ -1789,13 +1741,12 @@ ZEND_METHOD(ReflectionFunctionAbstract, isClosure) ZEND_METHOD(ReflectionFunctionAbstract, getClosureThis) { reflection_object *intern; - zval* closure_this; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT(); if (!Z_ISUNDEF(intern->obj)) { - closure_this = zend_get_closure_this_ptr(&intern->obj); + zval *closure_this = zend_get_closure_this_ptr(&intern->obj); if (!Z_ISUNDEF_P(closure_this)) { RETURN_OBJ_COPY(Z_OBJ_P(closure_this)); } @@ -1807,12 +1758,11 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureThis) ZEND_METHOD(ReflectionFunctionAbstract, getClosureScopeClass) { reflection_object *intern; - const zend_function *closure_func; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT(); if (!Z_ISUNDEF(intern->obj)) { - closure_func = zend_get_closure_method_def(Z_OBJ(intern->obj)); + const zend_function *closure_func = zend_get_closure_method_def(Z_OBJ(intern->obj)); if (closure_func && closure_func->common.scope) { zend_reflection_class_factory(closure_func->common.scope, return_value); } @@ -1832,8 +1782,9 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureCalledClass) zend_function *closure_func; zend_object *object; if (Z_OBJ_HANDLER(intern->obj, get_closure) - && Z_OBJ_HANDLER(intern->obj, get_closure)(Z_OBJ(intern->obj), &called_scope, &closure_func, &object, true) == SUCCESS - && closure_func && (called_scope || closure_func->common.scope)) { + && Z_OBJ_HANDLER(intern->obj, get_closure)(Z_OBJ(intern->obj), &called_scope, &closure_func, &object, true) == SUCCESS + && closure_func && (called_scope || closure_func->common.scope) + ) { zend_reflection_class_factory(called_scope ? called_scope : closure_func->common.scope, return_value); } } @@ -1844,7 +1795,6 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureCalledClass) ZEND_METHOD(ReflectionFunctionAbstract, getClosureUsedVariables) { reflection_object *intern; - const zend_function *closure_func; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT(); @@ -1853,7 +1803,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getClosureUsedVariables) RETURN_EMPTY_ARRAY(); } - closure_func = zend_get_closure_method_def(Z_OBJ(intern->obj)); + const zend_function *closure_func = zend_get_closure_method_def(Z_OBJ(intern->obj)); if (closure_func == NULL || closure_func->type != ZEND_USER_FUNCTION || closure_func->op_array.static_variables == NULL @@ -2013,12 +1963,8 @@ ZEND_METHOD(ReflectionFunctionAbstract, getDocComment) GET_REFLECTION_OBJECT_PTR(fptr); - if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - RETURN_STR_COPY(fptr->op_array.doc_comment); - } - - if (fptr->type == ZEND_INTERNAL_FUNCTION && ((zend_internal_function *) fptr)->doc_comment) { - RETURN_STR_COPY(((zend_internal_function *) fptr)->doc_comment); + if (fptr->common.doc_comment) { + RETURN_STR_COPY(fptr->common.doc_comment); } RETURN_FALSE; @@ -2030,10 +1976,10 @@ ZEND_METHOD(ReflectionFunctionAbstract, getAttributes) { reflection_object *intern; zend_function *fptr; - uint32_t target; GET_REFLECTION_OBJECT_PTR(fptr); - + + uint32_t target; if (fptr->common.scope && (fptr->common.fn_flags & (ZEND_ACC_CLOSURE|ZEND_ACC_FAKE_CLOSURE)) != ZEND_ACC_CLOSURE) { target = ZEND_ATTRIBUTE_TARGET_METHOD; } else { @@ -2057,10 +2003,8 @@ ZEND_METHOD(ReflectionFunctionAbstract, getStaticVariables) /* Return an empty array in case no static variables exist */ if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.static_variables != NULL) { - HashTable *ht; - array_init(return_value); - ht = ZEND_MAP_PTR_GET(fptr->op_array.static_variables_ptr); + HashTable *ht = ZEND_MAP_PTR_GET(fptr->op_array.static_variables_ptr); if (!ht) { ht = zend_array_dup(fptr->op_array.static_variables); ZEND_MAP_PTR_SET(fptr->op_array.static_variables_ptr, ht); @@ -2075,11 +2019,9 @@ ZEND_METHOD(ReflectionFunctionAbstract, getStaticVariables) /* {{{ Invokes the function */ ZEND_METHOD(ReflectionFunction, invoke) { - zval retval; zval *params; uint32_t num_args; HashTable *named_params; - zend_fcall_info_cache fcc; reflection_object *intern; zend_function *fptr; @@ -2089,6 +2031,7 @@ ZEND_METHOD(ReflectionFunction, invoke) GET_REFLECTION_OBJECT_PTR(fptr); + zend_fcall_info_cache fcc; fcc.function_handler = fptr; fcc.called_scope = NULL; fcc.object = NULL; @@ -2098,6 +2041,7 @@ ZEND_METHOD(ReflectionFunction, invoke) Z_OBJ(intern->obj), &fcc.called_scope, &fcc.function_handler, &fcc.object, false); } + zval retval; zend_call_known_fcc(&fcc, &retval, num_args, params, named_params); if (Z_ISREF(retval)) { @@ -2110,8 +2054,6 @@ ZEND_METHOD(ReflectionFunction, invoke) /* {{{ Invokes the function and pass its arguments as array. */ ZEND_METHOD(ReflectionFunction, invokeArgs) { - zval retval; - zend_fcall_info_cache fcc; reflection_object *intern; zend_function *fptr; HashTable *params; @@ -2122,6 +2064,7 @@ ZEND_METHOD(ReflectionFunction, invokeArgs) GET_REFLECTION_OBJECT_PTR(fptr); + zend_fcall_info_cache fcc; fcc.function_handler = fptr; fcc.called_scope = NULL; fcc.object = NULL; @@ -2131,6 +2074,7 @@ ZEND_METHOD(ReflectionFunction, invokeArgs) Z_OBJ(intern->obj), &fcc.called_scope, &fcc.function_handler, &fcc.object, false); } + zval retval; zend_call_known_fcc(&fcc, &retval, /* num_params */ 0, /* params */ NULL, params); if (Z_ISREF(retval)) { @@ -2159,13 +2103,12 @@ ZEND_METHOD(ReflectionFunctionAbstract, getNumberOfParameters) { reflection_object *intern; zend_function *fptr; - uint32_t num_args; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(fptr); - num_args = fptr->common.num_args; + uint32_t num_args = fptr->common.num_args; if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } @@ -2193,15 +2136,13 @@ ZEND_METHOD(ReflectionFunctionAbstract, getParameters) { reflection_object *intern; zend_function *fptr; - uint32_t i, num_args; - struct _zend_arg_info *arg_info; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(fptr); - arg_info= fptr->common.arg_info; - num_args = fptr->common.num_args; + struct _zend_arg_info *arg_info = fptr->common.arg_info; + uint32_t num_args = fptr->common.num_args; if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } @@ -2211,7 +2152,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getParameters) } array_init(return_value); - for (i = 0; i < num_args; i++) { + for (uint32_t i = 0; i < num_args; i++) { zval parameter; reflection_parameter_factory( @@ -2234,7 +2175,6 @@ ZEND_METHOD(ReflectionFunctionAbstract, getExtension) { reflection_object *intern; zend_function *fptr; - zend_internal_function *internal; ZEND_PARSE_PARAMETERS_NONE(); @@ -2244,7 +2184,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getExtension) RETURN_NULL(); } - internal = (zend_internal_function *)fptr; + zend_internal_function *internal = (zend_internal_function *)fptr; if (internal->module) { reflection_extension_factory(return_value, internal->module); } else { @@ -2258,7 +2198,6 @@ ZEND_METHOD(ReflectionFunctionAbstract, getExtensionName) { reflection_object *intern; zend_function *fptr; - zend_internal_function *internal; ZEND_PARSE_PARAMETERS_NONE(); @@ -2268,7 +2207,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getExtensionName) RETURN_FALSE; } - internal = (zend_internal_function *)fptr; + zend_internal_function *internal = (zend_internal_function *)fptr; if (internal->module) { RETURN_STRING(internal->module->name); } else { @@ -2280,11 +2219,10 @@ ZEND_METHOD(ReflectionFunctionAbstract, getExtensionName) /* {{{ */ ZEND_METHOD(ReflectionGenerator, __construct) { - zval *generator, *object; - reflection_object *intern; + zval *generator; - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &generator, zend_ce_generator) == FAILURE) { RETURN_THROWS(); @@ -2311,10 +2249,9 @@ ZEND_METHOD(ReflectionGenerator, getTrace) { zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT; zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj); - zend_generator *root_generator; zend_execute_data *ex_backup = EG(current_execute_data); zend_execute_data *ex = generator->execute_data; - zend_execute_data *root_prev = NULL, *cur_prev; + zend_execute_data *root_prev = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &options) == FAILURE) { RETURN_THROWS(); @@ -2322,9 +2259,9 @@ ZEND_METHOD(ReflectionGenerator, getTrace) REFLECTION_CHECK_VALID_GENERATOR(ex) - root_generator = zend_generator_get_current(generator); + zend_generator *root_generator = zend_generator_get_current(generator); - cur_prev = generator->execute_data->prev_execute_data; + zend_execute_data *cur_prev = generator->execute_data->prev_execute_data; if (generator == root_generator) { generator->execute_data->prev_execute_data = NULL; } else { @@ -2413,13 +2350,12 @@ ZEND_METHOD(ReflectionGenerator, getExecutingGenerator) { zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj); zend_execute_data *ex = generator->execute_data; - zend_generator *current; ZEND_PARSE_PARAMETERS_NONE(); REFLECTION_CHECK_VALID_GENERATOR(ex) - current = zend_generator_get_current(generator); + zend_generator *current = zend_generator_get_current(generator); RETURN_OBJ_COPY(¤t->std); } /* }}} */ @@ -2441,12 +2377,7 @@ ZEND_METHOD(ReflectionParameter, __construct) zval *reference; zend_string *arg_name = NULL; zend_long position; - zval *object; - zval *prop_name; - reflection_object *intern; zend_function *fptr; - struct _zend_arg_info *arg_info; - uint32_t num_args; zend_class_entry *ce = NULL; bool is_closure = false; @@ -2455,101 +2386,100 @@ ZEND_METHOD(ReflectionParameter, __construct) Z_PARAM_STR_OR_LONG(arg_name, position) ZEND_PARSE_PARAMETERS_END(); - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); /* First, find the function */ switch (Z_TYPE_P(reference)) { - case IS_STRING: - { - zend_string *fname = Z_STR_P(reference); - zend_string *lcname; - if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) { - /* Ignore leading "\" */ - ALLOCA_FLAG(use_heap) - ZSTR_ALLOCA_ALLOC(lcname, ZSTR_LEN(fname) - 1, use_heap); - zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(fname) + 1, ZSTR_LEN(fname) - 1); - fptr = zend_fetch_function(lcname); - ZSTR_ALLOCA_FREE(lcname, use_heap); - } else { - lcname = zend_string_tolower(fname); - fptr = zend_fetch_function(lcname); - zend_string_release(lcname); - } - if (!fptr) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Function %s() does not exist", Z_STRVAL_P(reference)); - RETURN_THROWS(); - } - ce = fptr->common.scope; + case IS_STRING: { + zend_string *fname = Z_STR_P(reference); + zend_string *lcname; + if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) { + /* Ignore leading "\" */ + ALLOCA_FLAG(use_heap) + ZSTR_ALLOCA_ALLOC(lcname, ZSTR_LEN(fname) - 1, use_heap); + zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(fname) + 1, ZSTR_LEN(fname) - 1); + fptr = zend_fetch_function(lcname); + ZSTR_ALLOCA_FREE(lcname, use_heap); + } else { + lcname = zend_string_tolower(fname); + fptr = zend_fetch_function(lcname); + zend_string_release(lcname); + } + if (!fptr) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Function %s() does not exist", Z_STRVAL_P(reference)); + RETURN_THROWS(); } + ce = fptr->common.scope; break; + } case IS_ARRAY: { - zval *classref; - zval *method; - zend_string *name, *lcname; - - if (((classref = zend_hash_index_find(Z_ARRVAL_P(reference), 0)) == NULL) - || ((method = zend_hash_index_find(Z_ARRVAL_P(reference), 1)) == NULL)) - { - zend_throw_exception(reflection_exception_ptr, "Expected array($object, $method) or array($classname, $method)", 0); - RETURN_THROWS(); - } - - if (Z_TYPE_P(classref) == IS_OBJECT) { - ce = Z_OBJCE_P(classref); - } else { - name = zval_try_get_string(classref); - if (UNEXPECTED(!name)) { - return; - } - if ((ce = zend_lookup_class(name)) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Class \"%s\" does not exist", ZSTR_VAL(name)); - zend_string_release(name); - RETURN_THROWS(); - } - zend_string_release(name); - } + zval *classref; + zval *method; + zend_string *name; + + if (((classref = zend_hash_index_find(Z_ARRVAL_P(reference), 0)) == NULL) + || ((method = zend_hash_index_find(Z_ARRVAL_P(reference), 1)) == NULL) + ) { + zend_throw_exception(reflection_exception_ptr, "Expected array($object, $method) or array($classname, $method)", 0); + RETURN_THROWS(); + } - name = zval_try_get_string(method); + if (Z_TYPE_P(classref) == IS_OBJECT) { + ce = Z_OBJCE_P(classref); + } else { + name = zval_try_get_string(classref); if (UNEXPECTED(!name)) { return; } - - lcname = zend_string_tolower(name); - if (Z_TYPE_P(classref) == IS_OBJECT && is_closure_invoke(ce, lcname) - && (fptr = zend_get_closure_invoke_method(Z_OBJ_P(classref))) != NULL) - { - /* nothing to do. don't set is_closure since is the invoke handler, - not the closure itself */ - } else if ((fptr = zend_hash_find_ptr(&ce->function_table, lcname)) == NULL) { + if ((ce = zend_lookup_class(name)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0, - "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name)); + "Class \"%s\" does not exist", ZSTR_VAL(name)); zend_string_release(name); - zend_string_release(lcname); RETURN_THROWS(); } zend_string_release(name); + } + + name = zval_try_get_string(method); + if (UNEXPECTED(!name)) { + return; + } + + zend_string *lcname = zend_string_tolower(name); + if (Z_TYPE_P(classref) == IS_OBJECT && is_closure_invoke(ce, lcname) + && (fptr = zend_get_closure_invoke_method(Z_OBJ_P(classref))) != NULL) + { + /* nothing to do. don't set is_closure since is the invoke handler, + not the closure itself */ + } else if ((fptr = zend_hash_find_ptr(&ce->function_table, lcname)) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name)); + zend_string_release(name); zend_string_release(lcname); + RETURN_THROWS(); } + zend_string_release(name); + zend_string_release(lcname); break; + } case IS_OBJECT: { - ce = Z_OBJCE_P(reference); + ce = Z_OBJCE_P(reference); - if (instanceof_function(ce, zend_ce_closure)) { - fptr = (zend_function *)zend_get_closure_method_def(Z_OBJ_P(reference)); - Z_ADDREF_P(reference); - is_closure = true; - } else if ((fptr = zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZEND_INVOKE_FUNC_NAME); - RETURN_THROWS(); - } + if (ce == zend_ce_closure) { + fptr = (zend_function *)zend_get_closure_method_def(Z_OBJ_P(reference)); + Z_ADDREF_P(reference); + is_closure = true; + } else if ((fptr = zend_hash_find_ptr(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZEND_INVOKE_FUNC_NAME); + RETURN_THROWS(); } break; + } default: zend_argument_error(reflection_exception_ptr, 1, "must be a string, an array(class, method), or a callable object, %s given", zend_zval_value_name(reference)); @@ -2557,21 +2487,20 @@ ZEND_METHOD(ReflectionParameter, __construct) } /* Now, search for the parameter */ - arg_info = fptr->common.arg_info; - num_args = fptr->common.num_args; + struct _zend_arg_info *arg_info = fptr->common.arg_info; + uint32_t num_args = fptr->common.num_args; if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { num_args++; } if (arg_name != NULL) { - uint32_t i; position = -1; - for (i = 0; i < num_args; i++) { - if (arg_info[i].name) { - if (zend_string_equals(arg_name, arg_info[i].name)) { - position = i; - break; - } + for (uint32_t i = 0; i < num_args; i++) { + if (arg_info[i].name + && zend_string_equals(arg_name, arg_info[i].name) + ) { + position = i; + break; } } if (position == -1) { @@ -2609,7 +2538,7 @@ ZEND_METHOD(ReflectionParameter, __construct) ZVAL_UNDEF(&intern->obj); } - prop_name = reflection_prop_name(object); + zval *prop_name = reflection_prop_name(object); zval_ptr_dtor(prop_name); ZVAL_STR_COPY(prop_name, arg_info[position].name); return; @@ -2635,7 +2564,7 @@ ZEND_METHOD(ReflectionParameter, __toString) ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(param); - _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, ""); + _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required); RETURN_STR(smart_str_extract(&str)); } @@ -2707,7 +2636,6 @@ ZEND_METHOD(ReflectionParameter, getClass) { reflection_object *intern; parameter_reference *param; - zend_class_entry *ce; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(param); @@ -2726,9 +2654,8 @@ ZEND_METHOD(ReflectionParameter, getClass) * TODO: Think about moving these checks to the compiler or some sort of * lint-mode. */ - zend_string *class_name; - - class_name = ZEND_TYPE_NAME(param->arg_info->type); + zend_class_entry *ce; + zend_string *class_name = ZEND_TYPE_NAME(param->arg_info->type); if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_SELF))) { ce = param->fptr->common.scope; if (!ce) { @@ -2796,7 +2723,6 @@ ZEND_METHOD(ReflectionParameter, isArray) { reflection_object *intern; parameter_reference *param; - uint32_t type_mask; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(param); @@ -2806,7 +2732,7 @@ ZEND_METHOD(ReflectionParameter, isArray) RETURN_FALSE; } - type_mask = ZEND_TYPE_PURE_MASK_WITHOUT_NULL(param->arg_info->type); + uint32_t type_mask = ZEND_TYPE_PURE_MASK_WITHOUT_NULL(param->arg_info->type); RETVAL_BOOL(type_mask == MAY_BE_ARRAY); } /* }}} */ @@ -2816,12 +2742,11 @@ ZEND_METHOD(ReflectionParameter, isCallable) { reflection_object *intern; parameter_reference *param; - uint32_t type_mask; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(param); - type_mask = ZEND_TYPE_PURE_MASK_WITHOUT_NULL(param->arg_info->type); + uint32_t type_mask = ZEND_TYPE_PURE_MASK_WITHOUT_NULL(param->arg_info->type); RETVAL_BOOL(type_mask == MAY_BE_CALLABLE); } /* }}} */ @@ -2840,7 +2765,7 @@ ZEND_METHOD(ReflectionParameter, allowsNull) } /* }}} */ -/* {{{ Returns whether this parameters is passed to by reference */ +/* {{{ Returns whether this parameter is passed to by reference */ ZEND_METHOD(ReflectionParameter, isPassedByReference) { reflection_object *intern; @@ -3121,12 +3046,12 @@ ZEND_METHOD(ReflectionNamedType, isBuiltin) /* }}} */ static void append_type(zval *return_value, zend_type type) { - zval reflection_type; /* Drop iterable BC bit for type list */ if (ZEND_TYPE_IS_ITERABLE_FALLBACK(type)) { ZEND_TYPE_FULL_MASK(type) &= ~_ZEND_TYPE_ITERABLE_BIT; } + zval reflection_type; reflection_type_factory(type, &reflection_type, false); zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &reflection_type); } @@ -3140,7 +3065,6 @@ ZEND_METHOD(ReflectionUnionType, getTypes) { reflection_object *intern; type_reference *param; - uint32_t type_mask; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(param); @@ -3156,7 +3080,7 @@ ZEND_METHOD(ReflectionUnionType, getTypes) append_type(return_value, (zend_type) ZEND_TYPE_INIT_CLASS(name, false, 0)); } - type_mask = ZEND_TYPE_PURE_MASK(param->type); + uint32_t type_mask = ZEND_TYPE_PURE_MASK(param->type); ZEND_ASSERT(!(type_mask & MAY_BE_VOID)); ZEND_ASSERT(!(type_mask & MAY_BE_NEVER)); if (type_mask & MAY_BE_STATIC) { @@ -3198,7 +3122,6 @@ ZEND_METHOD(ReflectionIntersectionType, getTypes) { reflection_object *intern; type_reference *param; - const zend_type *list_type; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(param); @@ -3206,7 +3129,7 @@ ZEND_METHOD(ReflectionIntersectionType, getTypes) ZEND_ASSERT(ZEND_TYPE_HAS_LIST(param->type)); array_init(return_value); - ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(param->type), list_type) { + ZEND_TYPE_LIST_FOREACH(ZEND_TYPE_LIST(param->type), const zend_type *list_type) { append_type(return_value, *list_type); } ZEND_TYPE_LIST_FOREACH_END(); } @@ -3224,11 +3147,6 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_ zend_string *class_name = NULL; char *method_name; size_t method_name_len; - char *lcname; - - zval *object; - reflection_object *intern; - zend_function *mptr; if (is_constructor) { if (ZEND_NUM_ARGS() == 1) { @@ -3266,14 +3184,13 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_ method_name_len = ZSTR_LEN(arg2_str); } else { char *tmp; - size_t tmp_len; char *name = ZSTR_VAL(arg1_str); if ((tmp = strstr(name, "::")) == NULL) { zend_argument_error(reflection_exception_ptr, 1, "must be a valid method name"); RETURN_THROWS(); } - tmp_len = tmp - name; + size_t tmp_len = tmp - name; class_name = zend_string_init(name, tmp_len, false); method_name = tmp + 2; @@ -3292,16 +3209,18 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_ zend_string_release(class_name); } + zval *object; if (is_constructor) { object = ZEND_THIS; } else { object_init_ex(return_value, execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr); object = return_value; } - intern = Z_REFLECTION_P(object); + reflection_object *intern = Z_REFLECTION_P(object); - lcname = zend_str_tolower_dup(method_name, method_name_len); + char *lcname = zend_str_tolower_dup(method_name, method_name_len); + zend_function *mptr; if (ce == zend_ce_closure && orig_obj && (method_name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && (mptr = zend_get_closure_invoke_method(orig_obj)) != NULL) @@ -3363,37 +3282,35 @@ ZEND_METHOD(ReflectionMethod, getClosure) if (mptr->common.fn_flags & ZEND_ACC_STATIC) { zend_create_fake_closure(return_value, mptr, mptr->common.scope, mptr->common.scope, NULL); - } else { - if (!obj) { - zend_argument_value_error(1, "cannot be null for non-static methods"); - RETURN_THROWS(); - } + return; + } + if (!obj) { + zend_argument_value_error(1, "cannot be null for non-static methods"); + RETURN_THROWS(); + } - if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope)) { - zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this method was declared in", 0); - RETURN_THROWS(); - } + if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope)) { + zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this method was declared in", 0); + RETURN_THROWS(); + } - /* This is an original closure object and __invoke is to be called. */ - if (Z_OBJCE_P(obj) == zend_ce_closure && - (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) - { - RETURN_OBJ_COPY(Z_OBJ_P(obj)); - } else { - zend_create_fake_closure(return_value, mptr, mptr->common.scope, Z_OBJCE_P(obj), obj); - } + /* This is an original closure object and __invoke is to be called. */ + if (Z_OBJCE_P(obj) == zend_ce_closure && + (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) + { + RETURN_OBJ_COPY(Z_OBJ_P(obj)); } + zend_create_fake_closure(return_value, mptr, mptr->common.scope, Z_OBJCE_P(obj), obj); } /* }}} */ /* {{{ reflection_method_invoke */ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, bool variadic) { - zval retval; zval *params = NULL, *object; HashTable *named_params = NULL; reflection_object *intern; - zend_function *mptr, *callback; + zend_function *mptr; uint32_t argc = 0; zend_class_entry *obj_ce; @@ -3475,7 +3392,8 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, bool variadic } } /* Copy the zend_function when calling via handler (e.g. Closure::__invoke()) */ - callback = _copy_function(mptr); + zend_function *callback = _copy_function(mptr); + zval retval; zend_call_known_function(callback, (object ? Z_OBJ_P(object) : NULL), intern->ce, &retval, argc, params, named_params); if (Z_ISREF(retval)) { @@ -3795,12 +3713,9 @@ ZEND_METHOD(ReflectionMethod, setAccessible) /* {{{ Constructor. Throws an Exception in case the given class constant does not exist */ ZEND_METHOD(ReflectionClassConstant, __construct) { - zval *object; zend_string *classname_str; zend_object *classname_obj; zend_string *constname; - reflection_object *intern; - zend_class_entry *ce; zend_class_constant *constant = NULL; ZEND_PARSE_PARAMETERS_START(2, 2) @@ -3808,17 +3723,16 @@ ZEND_METHOD(ReflectionClassConstant, __construct) Z_PARAM_STR(constname) ZEND_PARSE_PARAMETERS_END(); + zend_class_entry *ce; if (classname_obj) { ce = classname_obj->ce; - } else { - if ((ce = zend_lookup_class(classname_str)) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(classname_str)); - RETURN_THROWS(); - } + } else if ((ce = zend_lookup_class(classname_str)) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(classname_str)); + RETURN_THROWS(); } - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); if ((constant = zend_hash_find_ptr(CE_CONSTANTS_TABLE(ce), constname)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0, "Constant %s::%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(constname)); @@ -4040,11 +3954,8 @@ ZEND_METHOD(ReflectionClassConstant, isDeprecated) /* {{{ reflection_class_object_ctor */ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, bool is_object) { - zval *object; zend_string *arg_class = NULL; zend_object *arg_obj; - reflection_object *intern; - zend_class_entry *ce; if (is_object) { ZEND_PARSE_PARAMETERS_START(1, 1) @@ -4056,8 +3967,8 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, bool is_o ZEND_PARSE_PARAMETERS_END(); } - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); /* Note: class entry name is interned, no need to destroy them */ if (arg_obj) { @@ -4068,6 +3979,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, bool is_o ZVAL_OBJ_COPY(&intern->obj, arg_obj); } } else { + zend_class_entry *ce; if ((ce = zend_lookup_class(arg_class)) == NULL) { if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", ZSTR_VAL(arg_class)); @@ -4092,13 +4004,10 @@ ZEND_METHOD(ReflectionClass, __construct) /* {{{ add_class_vars */ static void add_class_vars(zend_class_entry *ce, bool statics, zval *return_value) { - zend_property_info *prop_info; - zval *prop, prop_copy; - zend_string *key; + zval prop_copy; - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { - if (((prop_info->flags & ZEND_ACC_PRIVATE) && - prop_info->ce != ce)) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, zend_string *key, zend_property_info *prop_info) { + if ((prop_info->flags & ZEND_ACC_PRIVATE) && prop_info->ce != ce) { continue; } @@ -4107,7 +4016,7 @@ static void add_class_vars(zend_class_entry *ce, bool statics, zval *return_valu continue; } - prop = property_get_default(prop_info); + zval *prop = property_get_default(prop_info); if (!prop || Z_ISUNDEF_P(prop)) { continue; } @@ -4118,10 +4027,10 @@ static void add_class_vars(zend_class_entry *ce, bool statics, zval *return_valu /* this is necessary to make it able to work with default array * properties, returned to user */ - if (Z_TYPE(prop_copy) == IS_CONSTANT_AST) { - if (UNEXPECTED(zval_update_constant_ex(&prop_copy, ce) != SUCCESS)) { - return; - } + if (Z_TYPE(prop_copy) == IS_CONSTANT_AST + && UNEXPECTED(zval_update_constant_ex(&prop_copy, ce) != SUCCESS) + ) { + return; } zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy); @@ -4134,9 +4043,6 @@ ZEND_METHOD(ReflectionClass, getStaticProperties) { reflection_object *intern; zend_class_entry *ce; - zend_property_info *prop_info; - zval *prop; - zend_string *key; ZEND_PARSE_PARAMETERS_NONE(); @@ -4162,16 +4068,15 @@ ZEND_METHOD(ReflectionClass, getStaticProperties) array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { - if (((prop_info->flags & ZEND_ACC_PRIVATE) && - prop_info->ce != ce)) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, zend_string *key, zend_property_info *prop_info) { + if ((prop_info->flags & ZEND_ACC_PRIVATE) && prop_info->ce != ce) { continue; } if ((prop_info->flags & ZEND_ACC_STATIC) == 0) { continue; } - prop = &CE_STATIC_MEMBERS(ce)[prop_info->offset]; + zval *prop = &CE_STATIC_MEMBERS(ce)[prop_info->offset]; ZVAL_DEINDIRECT(prop); if (ZEND_TYPE_IS_SET(prop_info->type) && Z_ISUNDEF_P(prop)) { @@ -4193,7 +4098,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue) reflection_object *intern; zend_class_entry *ce; zend_string *name; - zval *prop, *def_value = NULL; + zval *def_value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &name, &def_value) == FAILURE) { RETURN_THROWS(); @@ -4207,7 +4112,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue) const zend_class_entry *old_scope = EG(fake_scope); EG(fake_scope) = ce; - prop = zend_std_get_static_property(ce, name, BP_VAR_IS); + zval *prop = zend_std_get_static_property(ce, name, BP_VAR_IS); EG(fake_scope) = old_scope; if (prop && !Z_ISUNDEF_P(prop)) { @@ -4233,9 +4138,8 @@ ZEND_METHOD(ReflectionClass, setStaticPropertyValue) { reflection_object *intern; zend_class_entry *ce; - zend_property_info *prop_info; zend_string *name; - zval *variable_ptr, *value; + zval *value; if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &name, &value) == FAILURE) { RETURN_THROWS(); @@ -4248,7 +4152,8 @@ ZEND_METHOD(ReflectionClass, setStaticPropertyValue) } const zend_class_entry *old_scope = EG(fake_scope); EG(fake_scope) = ce; - variable_ptr = zend_std_get_static_property_with_info(ce, name, BP_VAR_W, &prop_info); + zend_property_info *prop_info; + zval *variable_ptr = zend_std_get_static_property_with_info(ce, name, BP_VAR_W, &prop_info); EG(fake_scope) = old_scope; if (!variable_ptr) { zend_clear_exception(); @@ -4459,14 +4364,14 @@ ZEND_METHOD(ReflectionClass, hasMethod) { reflection_object *intern; zend_class_entry *ce; - zend_string *name, *lc_name; + zend_string *name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { RETURN_THROWS(); } GET_REFLECTION_OBJECT_PTR(ce); - lc_name = zend_string_tolower(name); + zend_string *lc_name = zend_string_tolower(name); RETVAL_BOOL(zend_hash_exists(&ce->function_table, lc_name) || is_closure_invoke(ce, lc_name)); zend_string_release(lc_name); } @@ -4477,16 +4382,16 @@ ZEND_METHOD(ReflectionClass, getMethod) { reflection_object *intern; zend_class_entry *ce; - zend_function *mptr; - zval obj_tmp; - zend_string *name, *lc_name; + zend_string *name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { RETURN_THROWS(); } GET_REFLECTION_OBJECT_PTR(ce); - lc_name = zend_string_tolower(name); + zend_string *lc_name = zend_string_tolower(name); + zend_function *mptr; + zval obj_tmp; if (!Z_ISUNDEF(intern->obj) && is_closure_invoke(ce, lc_name) && (mptr = zend_get_closure_invoke_method(Z_OBJ(intern->obj))) != NULL) { @@ -4531,7 +4436,6 @@ ZEND_METHOD(ReflectionClass, getMethods) { reflection_object *intern; zend_class_entry *ce; - zend_function *mptr; zend_long filter; bool filter_is_null = true; @@ -4546,29 +4450,30 @@ ZEND_METHOD(ReflectionClass, getMethods) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, mptr) { + ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) { _addmethod(mptr, ce, Z_ARRVAL_P(return_value), filter); } ZEND_HASH_FOREACH_END(); - if (instanceof_function(ce, zend_ce_closure)) { - bool has_obj = Z_TYPE(intern->obj) != IS_UNDEF; - zval obj_tmp; - zend_object *obj; - if (!has_obj) { - object_init_ex(&obj_tmp, ce); - obj = Z_OBJ(obj_tmp); - } else { - obj = Z_OBJ(intern->obj); - } - zend_function *closure = zend_get_closure_invoke_method(obj); - if (closure) { - if (!_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter)) { - _free_function(closure); - } - } - if (!has_obj) { - zval_ptr_dtor(&obj_tmp); - } + if (ce != zend_ce_closure) { + return; + } + bool has_obj = Z_TYPE(intern->obj) != IS_UNDEF; + zval obj_tmp; + zend_object *obj; + if (!has_obj) { + object_init_ex(&obj_tmp, ce); + obj = Z_OBJ(obj_tmp); + } else { + obj = Z_OBJ(intern->obj); + } + zend_function *closure = zend_get_closure_invoke_method(obj); + if (closure + && !_addmethod(closure, ce, Z_ARRVAL_P(return_value), filter) + ) { + _free_function(closure); + } + if (!has_obj) { + zval_ptr_dtor(&obj_tmp); } } /* }}} */ @@ -4577,7 +4482,6 @@ ZEND_METHOD(ReflectionClass, getMethods) ZEND_METHOD(ReflectionClass, hasProperty) { reflection_object *intern; - zend_property_info *property_info; zend_class_entry *ce; zend_string *name; @@ -4586,9 +4490,11 @@ ZEND_METHOD(ReflectionClass, hasProperty) } GET_REFLECTION_OBJECT_PTR(ce); + zend_property_info *property_info; if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL - && (!(property_info->flags & ZEND_ACC_PRIVATE) - || property_info->ce == ce)) { + && (!(property_info->flags & ZEND_ACC_PRIVATE) + || property_info->ce == ce) + ) { RETURN_TRUE; } if (Z_TYPE(intern->obj) != IS_UNDEF) { @@ -4604,20 +4510,19 @@ ZEND_METHOD(ReflectionClass, hasProperty) ZEND_METHOD(ReflectionClass, getProperty) { reflection_object *intern; - zend_class_entry *ce, *ce2; - zend_property_info *property_info; - zend_string *name, *classname; - char *tmp, *str_name; - size_t classname_len, str_name_len; + zend_class_entry *ce; + zend_string *name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { RETURN_THROWS(); } GET_REFLECTION_OBJECT_PTR(ce); + zend_property_info *property_info; if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL - && (!(property_info->flags & ZEND_ACC_PRIVATE) - || property_info->ce == ce)) { + && (!(property_info->flags & ZEND_ACC_PRIVATE) + || property_info->ce == ce) + ) { reflection_property_factory(ce, name, property_info, return_value); return; } @@ -4628,14 +4533,15 @@ ZEND_METHOD(ReflectionClass, getProperty) return; } } - str_name = ZSTR_VAL(name); + char *str_name = ZSTR_VAL(name); + char *tmp; if ((tmp = strstr(ZSTR_VAL(name), "::")) != NULL) { - classname_len = tmp - ZSTR_VAL(name); - classname = zend_string_init(ZSTR_VAL(name), classname_len, false); - str_name_len = ZSTR_LEN(name) - (classname_len + 2); + size_t classname_len = tmp - ZSTR_VAL(name); + zend_string *classname = zend_string_init(ZSTR_VAL(name), classname_len, false); + size_t str_name_len = ZSTR_LEN(name) - (classname_len + 2); str_name = tmp + 2; - ce2 = zend_lookup_class(classname); + zend_class_entry *ce2 = zend_lookup_class(classname); if (!ce2) { if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1, "Class \"%s\" does not exist", ZSTR_VAL(classname)); @@ -4653,8 +4559,9 @@ ZEND_METHOD(ReflectionClass, getProperty) property_info = zend_hash_str_find_ptr(&ce->properties_info, str_name, str_name_len); if (property_info != NULL - && (!(property_info->flags & ZEND_ACC_PRIVATE) - || property_info->ce == ce)) { + && (!(property_info->flags & ZEND_ACC_PRIVATE) + || property_info->ce == ce) + ) { reflection_property_factory_str(ce, str_name, str_name_len, property_info, return_value); return; } @@ -4681,8 +4588,6 @@ static void _addproperty(zend_property_info *pptr, zend_string *key, zend_class_ /* {{{ _adddynproperty */ static void _adddynproperty(zval *ptr, zend_string *key, zend_class_entry *ce, zval *retval) { - zval property; - /* under some circumstances, the properties hash table may contain numeric * properties (e.g. when casting from array). This is a WON'T FIX bug, at * least for the moment. Ignore these */ @@ -4695,6 +4600,7 @@ static void _adddynproperty(zval *ptr, zend_string *key, zend_class_entry *ce, z return; } + zval property; reflection_property_factory(ce, key, NULL, &property); add_next_index_zval(retval, &property); } @@ -4705,8 +4611,6 @@ ZEND_METHOD(ReflectionClass, getProperties) { reflection_object *intern; zend_class_entry *ce; - zend_string *key; - zend_property_info *prop_info; zend_long filter; bool filter_is_null = true; @@ -4721,14 +4625,14 @@ ZEND_METHOD(ReflectionClass, getProperties) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { + zend_string *key; + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, key, zend_property_info *prop_info) { _addproperty(prop_info, key, ce, Z_ARRVAL_P(return_value), filter); } ZEND_HASH_FOREACH_END(); if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) { HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(Z_OBJ(intern->obj)); - zval *prop; - ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) { + ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, zval *prop) { _adddynproperty(prop, key, ce, return_value); } ZEND_HASH_FOREACH_END(); } @@ -4756,9 +4660,6 @@ ZEND_METHOD(ReflectionClass, getConstants) { reflection_object *intern; zend_class_entry *ce; - zend_string *key; - zend_class_constant *constant; - zval val; zend_long filter; bool filter_is_null = true; @@ -4778,7 +4679,8 @@ ZEND_METHOD(ReflectionClass, getConstants) } array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(constants_table, key, constant) { + zval val; + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(constants_table, zend_string *key, zend_class_constant *constant) { if (UNEXPECTED(Z_TYPE(constant->value) == IS_CONSTANT_AST && zend_update_class_constant(constant, key, constant->ce) != SUCCESS)) { RETURN_THROWS(); } @@ -4796,8 +4698,6 @@ ZEND_METHOD(ReflectionClass, getReflectionConstants) { reflection_object *intern; zend_class_entry *ce; - zend_string *name; - zend_class_constant *constant; zend_long filter; bool filter_is_null = true; @@ -4817,7 +4717,7 @@ ZEND_METHOD(ReflectionClass, getReflectionConstants) } array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(constants_table, name, constant) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(constants_table, zend_string *name, zend_class_constant *constant) { if (ZEND_CLASS_CONST_FLAGS(constant) & filter) { zval class_const; reflection_class_constant_factory(name, constant, &class_const); @@ -4832,17 +4732,16 @@ ZEND_METHOD(ReflectionClass, getConstant) { reflection_object *intern; zend_class_entry *ce; - const HashTable *constants_table; - zend_class_constant *c; - zend_string *name, *key; + zend_string *name; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { RETURN_THROWS(); } GET_REFLECTION_OBJECT_PTR(ce); - constants_table = CE_CONSTANTS_TABLE(ce); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(constants_table, key, c) { + const HashTable *constants_table = CE_CONSTANTS_TABLE(ce); + zend_class_constant *c; + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(constants_table, zend_string *key, c) { if (UNEXPECTED(Z_TYPE(c->value) == IS_CONSTANT_AST && zend_update_class_constant(c, key, c->ce) != SUCCESS)) { RETURN_THROWS(); } @@ -4864,7 +4763,6 @@ ZEND_METHOD(ReflectionClass, getReflectionConstant) { reflection_object *intern; zend_class_entry *ce; - zend_class_constant *constant; zend_string *name; GET_REFLECTION_OBJECT_PTR(ce); @@ -4872,6 +4770,7 @@ ZEND_METHOD(ReflectionClass, getReflectionConstant) RETURN_THROWS(); } + zend_class_constant *constant; if ((constant = zend_hash_find_ptr(CE_CONSTANTS_TABLE(ce), name)) == NULL) { RETURN_FALSE; } @@ -4906,7 +4805,6 @@ ZEND_METHOD(ReflectionClass, isCloneable) { reflection_object *intern; zend_class_entry *ce; - zval obj; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ce); @@ -4919,6 +4817,7 @@ ZEND_METHOD(ReflectionClass, isCloneable) if (!Z_ISUNDEF(intern->obj)) { RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL); } else { + zval obj; if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) { return; } @@ -5003,7 +4902,6 @@ ZEND_METHOD(ReflectionClass, newInstance) { reflection_object *intern; zend_class_entry *ce; - zend_function *constructor; GET_REFLECTION_OBJECT_PTR(ce); @@ -5013,21 +4911,20 @@ ZEND_METHOD(ReflectionClass, newInstance) const zend_class_entry *old_scope = EG(fake_scope); EG(fake_scope) = ce; - constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value)); + zend_function *constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value)); EG(fake_scope) = old_scope; /* Run the constructor if there is one */ if (constructor) { - zval *params; - int num_args; - HashTable *named_params; - if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %s", ZSTR_VAL(ce->name)); zval_ptr_dtor(return_value); RETURN_NULL(); } + zval *params; + int num_args; + HashTable *named_params; ZEND_PARSE_PARAMETERS_START(0, -1) Z_PARAM_VARIADIC_WITH_NAMED(params, num_args, named_params) ZEND_PARSE_PARAMETERS_END(); @@ -5070,9 +4967,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs) { reflection_object *intern; zend_class_entry *ce; - int argc = 0; HashTable *args = NULL; - zend_function *constructor; GET_REFLECTION_OBJECT_PTR(ce); @@ -5080,6 +4975,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs) RETURN_THROWS(); } + int argc = 0; if (args) { argc = zend_hash_num_elements(args); } @@ -5090,7 +4986,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs) const zend_class_entry *old_scope = EG(fake_scope); EG(fake_scope) = ce; - constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value)); + zend_function *constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value)); EG(fake_scope) = old_scope; /* Run the constructor if there is one */ @@ -5300,7 +5196,8 @@ ZEND_METHOD(ReflectionClass, getLazyInitializer) ZEND_PARSE_PARAMETERS_END(); if (!zend_object_is_lazy(object) - || zend_lazy_object_initialized(object)) { + || zend_lazy_object_initialized(object) + ) { RETURN_NULL(); } @@ -5318,11 +5215,9 @@ ZEND_METHOD(ReflectionClass, getInterfaces) GET_REFLECTION_OBJECT_PTR(ce); if (ce->num_interfaces) { - uint32_t i; - ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED); array_init(return_value); - for (i=0; i < ce->num_interfaces; i++) { + for (uint32_t i=0; i < ce->num_interfaces; i++) { zval interface; zend_reflection_class_factory(ce->interfaces[i], &interface); zend_hash_update(Z_ARRVAL_P(return_value), ce->interfaces[i]->name, &interface); @@ -5338,7 +5233,6 @@ ZEND_METHOD(ReflectionClass, getInterfaceNames) { reflection_object *intern; zend_class_entry *ce; - uint32_t i; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ce); @@ -5351,7 +5245,7 @@ ZEND_METHOD(ReflectionClass, getInterfaceNames) ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED); array_init(return_value); - for (i=0; i < ce->num_interfaces; i++) { + for (uint32_t i=0; i < ce->num_interfaces; i++) { add_next_index_str(return_value, zend_string_copy(ce->interfaces[i]->name)); } } @@ -5362,7 +5256,6 @@ ZEND_METHOD(ReflectionClass, getTraits) { reflection_object *intern; zend_class_entry *ce; - uint32_t i; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ce); @@ -5373,11 +5266,10 @@ ZEND_METHOD(ReflectionClass, getTraits) array_init(return_value); - for (i=0; i < ce->num_traits; i++) { + for (uint32_t i=0; i < ce->num_traits; i++) { zval trait; - zend_class_entry *trait_ce; - trait_ce = zend_fetch_class_by_name(ce->trait_names[i].name, + zend_class_entry *trait_ce = zend_fetch_class_by_name(ce->trait_names[i].name, ce->trait_names[i].lc_name, ZEND_FETCH_CLASS_TRAIT); ZEND_ASSERT(trait_ce); zend_reflection_class_factory(trait_ce, &trait); @@ -5391,7 +5283,6 @@ ZEND_METHOD(ReflectionClass, getTraitNames) { reflection_object *intern; zend_class_entry *ce; - uint32_t i; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ce); @@ -5402,7 +5293,7 @@ ZEND_METHOD(ReflectionClass, getTraitNames) array_init(return_value); - for (i=0; i < ce->num_traits; i++) { + for (uint32_t i=0; i < ce->num_traits; i++) { add_next_index_str(return_value, zend_string_copy(ce->trait_names[i].name)); } } @@ -5417,43 +5308,38 @@ ZEND_METHOD(ReflectionClass, getTraitAliases) ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ce); + if (!ce->trait_aliases) { + RETURN_EMPTY_ARRAY(); + } + + array_init(return_value); + for (uint32_t i = 0; ce->trait_aliases[i]; i++) { + zend_trait_method_reference *cur_ref = &ce->trait_aliases[i]->trait_method; - if (ce->trait_aliases) { - uint32_t i = 0; + if (!ce->trait_aliases[i]->alias) { + continue; + } + zend_string *class_name = cur_ref->class_name; - array_init(return_value); - while (ce->trait_aliases[i]) { - zend_string *mname; - zend_trait_method_reference *cur_ref = &ce->trait_aliases[i]->trait_method; - - if (ce->trait_aliases[i]->alias) { - zend_string *class_name = cur_ref->class_name; - - if (!class_name) { - uint32_t j = 0; - zend_string *lcname = zend_string_tolower(cur_ref->method_name); - - for (j = 0; j < ce->num_traits; j++) { - zend_class_entry *trait = - zend_hash_find_ptr(CG(class_table), ce->trait_names[j].lc_name); - ZEND_ASSERT(trait && "Trait must exist"); - if (zend_hash_exists(&trait->function_table, lcname)) { - class_name = trait->name; - break; - } - } - zend_string_release_ex(lcname, false); - ZEND_ASSERT(class_name != NULL); - } + if (!class_name) { + zend_string *lcname = zend_string_tolower(cur_ref->method_name); - mname = zend_string_alloc(ZSTR_LEN(class_name) + ZSTR_LEN(cur_ref->method_name) + 2, false); - snprintf(ZSTR_VAL(mname), ZSTR_LEN(mname) + 1, "%s::%s", ZSTR_VAL(class_name), ZSTR_VAL(cur_ref->method_name)); - add_assoc_str_ex(return_value, ZSTR_VAL(ce->trait_aliases[i]->alias), ZSTR_LEN(ce->trait_aliases[i]->alias), mname); + for (uint32_t j = 0; j < ce->num_traits; j++) { + zend_class_entry *trait = + zend_hash_find_ptr(CG(class_table), ce->trait_names[j].lc_name); + ZEND_ASSERT(trait && "Trait must exist"); + if (zend_hash_exists(&trait->function_table, lcname)) { + class_name = trait->name; + break; + } } - i++; + zend_string_release_ex(lcname, false); + ZEND_ASSERT(class_name != NULL); } - } else { - RETURN_EMPTY_ARRAY(); + + zend_string *mname = zend_string_alloc(ZSTR_LEN(class_name) + ZSTR_LEN(cur_ref->method_name) + 2, false); + snprintf(ZSTR_VAL(mname), ZSTR_LEN(mname) + 1, "%s::%s", ZSTR_VAL(class_name), ZSTR_VAL(cur_ref->method_name)); + add_assoc_str_ex(return_value, ZSTR_VAL(ce->trait_aliases[i]->alias), ZSTR_LEN(ce->trait_aliases[i]->alias), mname); } } /* }}} */ @@ -5478,7 +5364,7 @@ ZEND_METHOD(ReflectionClass, getParentClass) /* {{{ Returns whether this class is a subclass of another class */ ZEND_METHOD(ReflectionClass, isSubclassOf) { - reflection_object *intern, *argument; + reflection_object *intern; zend_class_entry *ce, *class_ce; zend_string *class_str; zend_object *class_obj; @@ -5488,7 +5374,7 @@ ZEND_METHOD(ReflectionClass, isSubclassOf) ZEND_PARSE_PARAMETERS_END(); if (class_obj) { - argument = reflection_object_from_obj(class_obj); + reflection_object *argument = reflection_object_from_obj(class_obj); if (argument->ptr == NULL) { zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object"); RETURN_THROWS(); @@ -5511,7 +5397,7 @@ ZEND_METHOD(ReflectionClass, isSubclassOf) /* {{{ Returns whether this class is a subclass of another class */ ZEND_METHOD(ReflectionClass, implementsInterface) { - reflection_object *intern, *argument; + reflection_object *intern; zend_string *interface_str; zend_class_entry *ce, *interface_ce; zend_object *interface_obj; @@ -5521,18 +5407,16 @@ ZEND_METHOD(ReflectionClass, implementsInterface) ZEND_PARSE_PARAMETERS_END(); if (interface_obj) { - argument = reflection_object_from_obj(interface_obj); + reflection_object *argument = reflection_object_from_obj(interface_obj); if (argument->ptr == NULL) { zend_throw_error(NULL, "Internal error: Failed to retrieve the argument's reflection object"); RETURN_THROWS(); } interface_ce = argument->ptr; - } else { - if ((interface_ce = zend_lookup_class(interface_str)) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, "Interface \"%s\" does not exist", ZSTR_VAL(interface_str)); - RETURN_THROWS(); - } + } else if ((interface_ce = zend_lookup_class(interface_str)) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Interface \"%s\" does not exist", ZSTR_VAL(interface_str)); + RETURN_THROWS(); } if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) { @@ -5667,39 +5551,34 @@ ZEND_METHOD(ReflectionProperty, __construct) zend_string *classname_str; zend_object *classname_obj; zend_string *name; - bool dynam_prop = false; - zval *object; - reflection_object *intern; zend_class_entry *ce; - zend_property_info *property_info = NULL; - property_reference *reference; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_OBJ_OR_STR(classname_obj, classname_str) Z_PARAM_STR(name) ZEND_PARSE_PARAMETERS_END(); - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); if (classname_obj) { ce = classname_obj->ce; - } else { - if ((ce = zend_lookup_class(classname_str)) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(classname_str)); - RETURN_THROWS(); - } + } else if ((ce = zend_lookup_class(classname_str)) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class \"%s\" does not exist", ZSTR_VAL(classname_str)); + RETURN_THROWS(); } - property_info = zend_hash_find_ptr(&ce->properties_info, name); + zend_property_info *property_info = zend_hash_find_ptr(&ce->properties_info, name); + bool dynam_prop = false; if (property_info == NULL - || ((property_info->flags & ZEND_ACC_PRIVATE) - && property_info->ce != ce)) { + || ((property_info->flags & ZEND_ACC_PRIVATE) + && property_info->ce != ce) + ) { /* Check for dynamic properties */ - if (property_info == NULL && classname_obj) { - if (zend_hash_exists(classname_obj->handlers->get_properties(classname_obj), name)) { - dynam_prop = true; - } + if (property_info == NULL && classname_obj + && zend_hash_exists(classname_obj->handlers->get_properties(classname_obj), name) + ) { + dynam_prop = true; } if (!dynam_prop) { zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name)); @@ -5721,7 +5600,7 @@ ZEND_METHOD(ReflectionProperty, __construct) reflection_free_property_reference(intern->ptr); } - reference = (property_reference*) emalloc(sizeof(property_reference)); + property_reference *reference = (property_reference*) emalloc(sizeof(property_reference)); reference->prop = dynam_prop ? NULL : property_info; reference->unmangled_name = zend_string_copy(name); memset(reference->cache_slot, 0, sizeof(reference->cache_slot)); @@ -5767,7 +5646,7 @@ ZEND_METHOD(ReflectionProperty, getMangledName) GET_REFLECTION_OBJECT_PTR(ref); if (ref->prop == NULL) { - RETURN_STR_COPY(ref->unmangled_name); + RETURN_STR_COPY(ref->unmangled_name); } RETURN_STR_COPY(ref->prop->name); @@ -5889,7 +5768,6 @@ ZEND_METHOD(ReflectionProperty, getValue) reflection_object *intern; property_reference *ref; zval *object = NULL; - zval *member_p = NULL; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL @@ -5899,49 +5777,48 @@ ZEND_METHOD(ReflectionProperty, getValue) GET_REFLECTION_OBJECT_PTR(ref); if (prop_get_flags(ref) & ZEND_ACC_STATIC) { - member_p = zend_read_static_property_ex(intern->ce, ref->unmangled_name, false); + zval *member_p = zend_read_static_property_ex(intern->ce, ref->unmangled_name, false); if (member_p) { RETURN_COPY_DEREF(member_p); } - } else { - zval rv; - - if (!object) { - zend_argument_type_error(1, "must be provided for instance properties"); - RETURN_THROWS(); - } + return; + } + if (!object) { + zend_argument_type_error(1, "must be provided for instance properties"); + RETURN_THROWS(); + } - /* TODO: Should this always use intern->ce? */ - if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) { - zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0); - RETURN_THROWS(); - } + /* TODO: Should this always use intern->ce? */ + if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) { + zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0); + RETURN_THROWS(); + } - if (ref->cache_slot[0] == Z_OBJCE_P(object)) { - uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1]; + if (ref->cache_slot[0] == Z_OBJCE_P(object)) { + uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1]; - if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { - zval *retval = OBJ_PROP(Z_OBJ_P(object), prop_offset); - if (EXPECTED(!Z_ISUNDEF_P(retval))) { - RETURN_COPY_DEREF(retval); - } + if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { + zval *retval = OBJ_PROP(Z_OBJ_P(object), prop_offset); + if (EXPECTED(!Z_ISUNDEF_P(retval))) { + RETURN_COPY_DEREF(retval); } } + } - const zend_class_entry *old_scope = EG(fake_scope); - EG(fake_scope) = intern->ce; - member_p = Z_OBJ_P(object)->handlers->read_property(Z_OBJ_P(object), - ref->unmangled_name, BP_VAR_R, ref->cache_slot, &rv); - EG(fake_scope) = old_scope; + zval rv; + const zend_class_entry *old_scope = EG(fake_scope); + EG(fake_scope) = intern->ce; + zval *member_p = Z_OBJ_P(object)->handlers->read_property(Z_OBJ_P(object), + ref->unmangled_name, BP_VAR_R, ref->cache_slot, &rv); + EG(fake_scope) = old_scope; - if (member_p != &rv) { - RETURN_COPY_DEREF(member_p); - } else { - if (Z_ISREF_P(member_p)) { - zend_unwrap_reference(member_p); - } - RETURN_COPY_VALUE(member_p); + if (member_p != &rv) { + RETURN_COPY_DEREF(member_p); + } else { + if (Z_ISREF_P(member_p)) { + zend_unwrap_reference(member_p); } + RETURN_COPY_VALUE(member_p); } } /* }}} */ @@ -5952,12 +5829,12 @@ ZEND_METHOD(ReflectionProperty, setValue) reflection_object *intern; property_reference *ref; zval *value; - zval *tmp; GET_REFLECTION_OBJECT_PTR(ref); if (prop_get_flags(ref) & ZEND_ACC_STATIC) { if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z", &value) == FAILURE) { + zval *tmp; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &tmp, &value) == FAILURE) { RETURN_THROWS(); } @@ -6146,13 +6023,13 @@ static zend_result reflection_property_check_lazy_compatible( return FAILURE; } - if (UNEXPECTED(object->handlers->write_property != zend_std_write_property)) { - if (!zend_class_can_be_lazy(object->ce)) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Can not use %s on internal class %s", - method, ZSTR_VAL(object->ce->name)); - return FAILURE; - } + if (UNEXPECTED(object->handlers->write_property != zend_std_write_property) + && !zend_class_can_be_lazy(object->ce) + ) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Can not use %s on internal class %s", + method, ZSTR_VAL(object->ce->name)); + return FAILURE; } ZEND_ASSERT(IS_VALID_PROPERTY_OFFSET(prop->offset)); @@ -6197,11 +6074,11 @@ PHPAPI void zend_reflection_property_set_raw_value_without_lazy_initialization( /* Object becomes non-lazy if this was the last lazy prop */ if (prop_was_lazy && !(Z_PROP_FLAG_P(var_ptr) & IS_PROP_LAZY) - && zend_object_is_lazy(object) - && !zend_lazy_object_initialized(object)) { - if (zend_lazy_object_decr_lazy_props(object)) { - zend_lazy_object_realize(object); - } + && zend_object_is_lazy(object) + && !zend_lazy_object_initialized(object) + && zend_lazy_object_decr_lazy_props(object) + ) { + zend_lazy_object_realize(object); } } @@ -6263,10 +6140,10 @@ ZEND_METHOD(ReflectionProperty, skipLazyInitialization) /* Object becomes non-lazy if this was the last lazy prop */ if (zend_object_is_lazy(object) - && !zend_lazy_object_initialized(object)) { - if (zend_lazy_object_decr_lazy_props(object)) { - zend_lazy_object_realize(object); - } + && !zend_lazy_object_initialized(object) + && zend_lazy_object_decr_lazy_props(object) + ) { + zend_lazy_object_realize(object); } } @@ -6314,37 +6191,34 @@ ZEND_METHOD(ReflectionProperty, isInitialized) RETURN_BOOL(!Z_ISUNDEF_P(member_p)); } RETURN_FALSE; - } else { - int retval; - - if (!object) { - zend_argument_type_error(1, "must be provided for instance properties"); - RETURN_THROWS(); - } + } + if (!object) { + zend_argument_type_error(1, "must be provided for instance properties"); + RETURN_THROWS(); + } - /* TODO: Should this always use intern->ce? */ - if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) { - zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0); - RETURN_THROWS(); - } + /* TODO: Should this always use intern->ce? */ + if (!instanceof_function(Z_OBJCE_P(object), ref->prop ? ref->prop->ce : intern->ce)) { + zend_throw_exception(reflection_exception_ptr, "Given object is not an instance of the class this property was declared in", 0); + RETURN_THROWS(); + } - if (ref->cache_slot[0] == Z_OBJCE_P(object)) { - uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1]; + if (ref->cache_slot[0] == Z_OBJCE_P(object)) { + uintptr_t prop_offset = (uintptr_t) ref->cache_slot[1]; - if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { - zval *value = OBJ_PROP(Z_OBJ_P(object), prop_offset); - RETURN_BOOL(!Z_ISUNDEF_P(value)); - } + if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) { + zval *value = OBJ_PROP(Z_OBJ_P(object), prop_offset); + RETURN_BOOL(!Z_ISUNDEF_P(value)); } + } - const zend_class_entry *old_scope = EG(fake_scope); - EG(fake_scope) = intern->ce; - retval = Z_OBJ_HT_P(object)->has_property(Z_OBJ_P(object), - ref->unmangled_name, ZEND_PROPERTY_EXISTS, ref->cache_slot); - EG(fake_scope) = old_scope; + const zend_class_entry *old_scope = EG(fake_scope); + EG(fake_scope) = intern->ce; + int retval = Z_OBJ_HT_P(object)->has_property(Z_OBJ_P(object), + ref->unmangled_name, ZEND_PROPERTY_EXISTS, ref->cache_slot); + EG(fake_scope) = old_scope; - RETVAL_BOOL(retval); - } + RETVAL_BOOL(retval); } /* }}} */ @@ -6353,12 +6227,11 @@ ZEND_METHOD(ReflectionProperty, getDeclaringClass) { reflection_object *intern; property_reference *ref; - zend_class_entry *ce; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ref); - ce = ref->prop ? ref->prop->ce : intern->ce; + zend_class_entry *ce = ref->prop ? ref->prop->ce : intern->ce; zend_reflection_class_factory(ce, return_value); } /* }}} */ @@ -6504,7 +6377,6 @@ ZEND_METHOD(ReflectionProperty, getDefaultValue) { reflection_object *intern; property_reference *ref; - zval *prop; ZEND_PARSE_PARAMETERS_NONE(); @@ -6522,7 +6394,7 @@ ZEND_METHOD(ReflectionProperty, getDefaultValue) return; } - prop = property_get_default(prop_info); + zval *prop = property_get_default(prop_info); if (!prop || Z_ISUNDEF_P(prop)) { zend_error( E_DEPRECATED, @@ -6538,10 +6410,10 @@ ZEND_METHOD(ReflectionProperty, getDefaultValue) /* this is necessary to make it able to work with default array * properties, returned to user */ - if (Z_TYPE_P(return_value) == IS_CONSTANT_AST) { - if (UNEXPECTED(zval_update_constant_ex(return_value, prop_info->ce) != SUCCESS)) { - RETURN_THROWS(); - } + if (Z_TYPE_P(return_value) == IS_CONSTANT_AST + && UNEXPECTED(zval_update_constant_ex(return_value, prop_info->ce) != SUCCESS) + ) { + RETURN_THROWS(); } } /* }}} */ @@ -6873,8 +6745,9 @@ ZEND_METHOD(ReflectionProperty, isWritable) retry:; zval *prop_val = OBJ_PROP(obj, prop->offset); if (Z_TYPE_P(prop_val) == IS_UNDEF - && zend_lazy_object_must_init(obj) - && (Z_PROP_FLAG_P(prop_val) & IS_PROP_LAZY)) { + && zend_lazy_object_must_init(obj) + && (Z_PROP_FLAG_P(prop_val) & IS_PROP_LAZY) + ) { obj = zend_lazy_object_init(obj); if (!obj) { RETURN_THROWS(); @@ -6892,17 +6765,15 @@ retry:; /* {{{ Constructor. Throws an Exception in case the given extension does not exist */ ZEND_METHOD(ReflectionExtension, __construct) { - zval *object; - reflection_object *intern; - zend_module_entry *module; zend_string *name_str; if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name_str) == FAILURE) { RETURN_THROWS(); } - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); + zend_module_entry *module; if ((module = zend_hash_find_ptr_lc(&module_registry, name_str)) == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0, "Extension \"%s\" does not exist", ZSTR_VAL(name_str)); @@ -6968,15 +6839,15 @@ ZEND_METHOD(ReflectionExtension, getFunctions) reflection_object *intern; zend_module_entry *module; zval function; - zend_function *fptr; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), fptr) { + ZEND_HASH_MAP_FOREACH_PTR(CG(function_table), zend_function *fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION - && fptr->internal_function.module == module) { + && fptr->internal_function.module == module + ) { reflection_function_factory(fptr, NULL, &function); zend_hash_update(Z_ARRVAL_P(return_value), fptr->common.function_name, &function); } @@ -6989,13 +6860,12 @@ ZEND_METHOD(ReflectionExtension, getConstants) { reflection_object *intern; zend_module_entry *module; - zend_constant *constant; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) { + ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), zend_constant *constant) { if (module->module_number == ZEND_CONSTANT_MODULE_NUMBER(constant)) { zval const_val; ZVAL_COPY_OR_DUP(&const_val, &constant->value); @@ -7025,13 +6895,12 @@ ZEND_METHOD(ReflectionExtension, getINIEntries) { reflection_object *intern; zend_module_entry *module; - zend_ini_entry *ini_entry; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), ini_entry) { + ZEND_HASH_MAP_FOREACH_PTR(EG(ini_directives), zend_ini_entry *ini_entry) { _addinientry(ini_entry, return_value, module->module_number); } ZEND_HASH_FOREACH_END(); } @@ -7066,14 +6935,12 @@ ZEND_METHOD(ReflectionExtension, getClasses) { reflection_object *intern; zend_module_entry *module; - zend_string *key; - zend_class_entry *ce; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), zend_string *key, zend_class_entry *ce) { add_extension_class(ce, key, return_value, module, true); } ZEND_HASH_FOREACH_END(); } @@ -7084,14 +6951,12 @@ ZEND_METHOD(ReflectionExtension, getClassNames) { reflection_object *intern; zend_module_entry *module; - zend_string *key; - zend_class_entry *ce; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), zend_string *key, zend_class_entry *ce) { add_extension_class(ce, key, return_value, module, false); } ZEND_HASH_FOREACH_END(); } @@ -7102,12 +6967,11 @@ ZEND_METHOD(ReflectionExtension, getDependencies) { reflection_object *intern; zend_module_entry *module; - const zend_module_dep *dep; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(module); - dep = module->deps; + const zend_module_dep *dep = module->deps; if (!dep) { RETURN_EMPTY_ARRAY(); @@ -7115,7 +6979,6 @@ ZEND_METHOD(ReflectionExtension, getDependencies) array_init(return_value); while (dep->name) { - zend_string *relation; char *rel_type; size_t len = 0; @@ -7146,7 +7009,7 @@ ZEND_METHOD(ReflectionExtension, getDependencies) len += strlen(dep->version) + 1; } - relation = zend_string_alloc(len, false); + zend_string *relation = zend_string_alloc(len, false); snprintf(ZSTR_VAL(relation), ZSTR_LEN(relation) + 1, "%s%s%s%s%s", rel_type, dep->rel ? " " : "", @@ -7201,9 +7064,6 @@ ZEND_METHOD(ReflectionExtension, isTemporary) /* {{{ Constructor. Throws an Exception in case the given Zend extension does not exist */ ZEND_METHOD(ReflectionZendExtension, __construct) { - zval *object; - reflection_object *intern; - zend_extension *extension; char *name_str; size_t name_len; @@ -7211,10 +7071,10 @@ ZEND_METHOD(ReflectionZendExtension, __construct) RETURN_THROWS(); } - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); - extension = zend_get_extension(name_str); + zend_extension *extension = zend_get_extension(name_str); if (!extension) { zend_throw_exception_ex(reflection_exception_ptr, 0, "Zend Extension \"%s\" does not exist", name_str); @@ -7345,16 +7205,15 @@ static bool is_ignorable_reference(const HashTable *ht, const zval *ref) { ZEND_METHOD(ReflectionReference, fromArrayElement) { HashTable *ht; - zval *item; zend_string *string_key = NULL; zend_long int_key = 0; - reflection_object *intern; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_ARRAY_HT(ht) Z_PARAM_STR_OR_LONG(string_key, int_key) ZEND_PARSE_PARAMETERS_END(); + zval *item; if (string_key) { item = zend_hash_find(ht, string_key); } else { @@ -7371,7 +7230,7 @@ ZEND_METHOD(ReflectionReference, fromArrayElement) } object_init_ex(return_value, reflection_reference_ptr); - intern = Z_REFLECTION_P(return_value); + reflection_object *intern = Z_REFLECTION_P(return_value); ZVAL_COPY(&intern->obj, item); intern->ref_type = REF_TYPE_OTHER; } @@ -7381,13 +7240,9 @@ ZEND_METHOD(ReflectionReference, fromArrayElement) * The format of the return value is unspecified and may change. */ ZEND_METHOD(ReflectionReference, getId) { - reflection_object *intern; - unsigned char digest[20]; - PHP_SHA1_CTX context; - ZEND_PARSE_PARAMETERS_NONE(); - intern = Z_REFLECTION_P(ZEND_THIS); + reflection_object *intern = Z_REFLECTION_P(ZEND_THIS); if (Z_TYPE(intern->obj) != IS_REFERENCE) { zend_throw_exception(reflection_exception_ptr, "Corrupted ReflectionReference object", 0); RETURN_THROWS(); @@ -7402,9 +7257,11 @@ ZEND_METHOD(ReflectionReference, getId) } /* SHA1(ref || key) to avoid directly exposing memory addresses. */ + PHP_SHA1_CTX context; PHP_SHA1Init(&context); PHP_SHA1Update(&context, (unsigned char *) &Z_REF(intern->obj), sizeof(zend_reference *)); PHP_SHA1Update(&context, REFLECTION_G(key), REFLECTION_KEY_LEN); + unsigned char digest[20]; PHP_SHA1Final(digest, &context); RETURN_STRINGL((char *) digest, sizeof(digest)); @@ -7508,9 +7365,6 @@ ZEND_METHOD(ReflectionAttribute, getArguments) reflection_object *intern; attribute_reference *attr; - zval tmp; - uint32_t i; - ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(attr); @@ -7520,7 +7374,8 @@ ZEND_METHOD(ReflectionAttribute, getArguments) array_init(return_value); - for (i = 0; i < attr->data->argc; i++) { + zval tmp; + for (uint32_t i = 0; i < attr->data->argc; i++) { if (FAILURE == zend_get_attribute_value(&tmp, attr->data, i, attr->scope)) { RETURN_THROWS(); } @@ -7540,19 +7395,18 @@ ZEND_METHOD(ReflectionAttribute, newInstance) { reflection_object *intern; attribute_reference *attr; - zend_attribute *marker; - - zend_class_entry *ce; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(attr); + zend_class_entry *ce; if (NULL == (ce = zend_lookup_class(attr->data->name))) { zend_throw_error(NULL, "Attribute class \"%s\" not found", ZSTR_VAL(attr->data->name)); RETURN_THROWS(); } + zend_attribute *marker; if (NULL == (marker = zend_get_attribute_str(ce->attributes, ZEND_STRL("attribute")))) { zend_throw_error(NULL, "Attempting to use non-attribute class \"%s\" as attribute", ZSTR_VAL(attr->data->name)); RETURN_THROWS(); @@ -7612,13 +7466,12 @@ ZEND_METHOD(ReflectionAttribute, newInstance) /* Repetition validation is done even if #[DelayedTargetValidation] is used * and so can be skipped for internal attributes. */ - if (ce->type == ZEND_USER_CLASS) { - if (!(flags & ZEND_ATTRIBUTE_IS_REPEATABLE)) { - if (zend_is_attribute_repeated(attr->attributes, attr->data)) { - zend_throw_error(NULL, "Attribute \"%s\" must not be repeated", ZSTR_VAL(attr->data->name)); - RETURN_THROWS(); - } - } + if (ce->type == ZEND_USER_CLASS + && !(flags & ZEND_ATTRIBUTE_IS_REPEATABLE) + && zend_is_attribute_repeated(attr->attributes, attr->data) + ) { + zend_throw_error(NULL, "Attribute \"%s\" must not be repeated", ZSTR_VAL(attr->data->name)); + RETURN_THROWS(); } zval obj; @@ -7696,15 +7549,13 @@ ZEND_METHOD(ReflectionEnum, getCases) { reflection_object *intern; zend_class_entry *ce; - zend_string *name; - zend_class_constant *constant; ZEND_PARSE_PARAMETERS_NONE(); GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), name, constant) { + ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(CE_CONSTANTS_TABLE(ce), zend_string *name, zend_class_constant *constant) { if (ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE) { zval class_const; reflection_enum_case_factory(ce, name, constant, &class_const); @@ -7814,11 +7665,10 @@ ZEND_METHOD(ReflectionEnumBackedCase, getBackingValue) /* {{{ proto ReflectionFiber::__construct(Fiber $fiber) */ ZEND_METHOD(ReflectionFiber, __construct) { - zval *fiber, *object; - reflection_object *intern; + zval *fiber; - object = ZEND_THIS; - intern = Z_REFLECTION_P(object); + zval *object = ZEND_THIS; + reflection_object *intern = Z_REFLECTION_P(object); ZEND_PARSE_PARAMETERS_START(1, 1) Z_PARAM_OBJECT_OF_CLASS(fiber, zend_ce_fiber) @@ -7852,7 +7702,6 @@ ZEND_METHOD(ReflectionFiber, getTrace) { zend_fiber *fiber = (zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj); zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT; - zend_execute_data *prev_execute_data; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL @@ -7861,7 +7710,7 @@ ZEND_METHOD(ReflectionFiber, getTrace) REFLECTION_CHECK_VALID_FIBER(fiber); - prev_execute_data = fiber->stack_bottom->prev_execute_data; + zend_execute_data *prev_execute_data = fiber->stack_bottom->prev_execute_data; fiber->stack_bottom->prev_execute_data = NULL; if (EG(active_fiber) != fiber) { @@ -7878,12 +7727,12 @@ ZEND_METHOD(ReflectionFiber, getTrace) ZEND_METHOD(ReflectionFiber, getExecutingLine) { const zend_fiber *fiber = (const zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj); - zend_execute_data *prev_execute_data; ZEND_PARSE_PARAMETERS_NONE(); REFLECTION_CHECK_VALID_FIBER(fiber); + zend_execute_data *prev_execute_data; if (EG(active_fiber) == fiber) { prev_execute_data = execute_data->prev_execute_data; } else { @@ -7902,12 +7751,12 @@ ZEND_METHOD(ReflectionFiber, getExecutingLine) ZEND_METHOD(ReflectionFiber, getExecutingFile) { const zend_fiber *fiber = (const zend_fiber *) Z_OBJ(Z_REFLECTION_P(ZEND_THIS)->obj); - zend_execute_data *prev_execute_data; ZEND_PARSE_PARAMETERS_NONE(); REFLECTION_CHECK_VALID_FIBER(fiber); + zend_execute_data *prev_execute_data; if (EG(active_fiber) == fiber) { prev_execute_data = execute_data->prev_execute_data; } else { @@ -8106,8 +7955,7 @@ static void reflection_constant_find_ext(INTERNAL_FUNCTION_PARAMETERS, bool only } RETURN_NULL(); } - zend_module_entry *module; - ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) { + ZEND_HASH_MAP_FOREACH_PTR(&module_registry, zend_module_entry *module) { if (module->module_number != module_number) { continue; }