diff options
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r-- | ext/reflection/php_reflection.c | 608 |
1 files changed, 250 insertions, 358 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index fe5f2178c6..ac623e1c05 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -20,8 +20,6 @@ +----------------------------------------------------------------------+ */ -/* $Id$ */ - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -46,12 +44,18 @@ #define reflection_update_property(object, name, value) do { \ zval member; \ - ZVAL_STRINGL(&member, name, sizeof(name)-1); \ + ZVAL_STR(&member, name); \ zend_std_write_property(object, &member, value, NULL); \ - if (Z_REFCOUNTED_P(value)) Z_DELREF_P(value); \ + Z_TRY_DELREF_P(value); \ zval_ptr_dtor(&member); \ } while (0) +#define reflection_update_property_name(object, value) \ + reflection_update_property(object, ZSTR_KNOWN(ZEND_STR_NAME), value) + +#define reflection_update_property_class(object, value) \ + reflection_update_property(object, ZSTR_KNOWN(ZEND_STR_CLASS), value) + /* Class entry pointers */ PHPAPI zend_class_entry *reflector_ptr; PHPAPI zend_class_entry *reflection_exception_ptr; @@ -70,14 +74,6 @@ PHPAPI zend_class_entry *reflection_class_constant_ptr; PHPAPI zend_class_entry *reflection_extension_ptr; PHPAPI zend_class_entry *reflection_zend_extension_ptr; -/* Method macros */ - -#define METHOD_NOTSTATIC(ce) \ - if ((Z_TYPE(EX(This)) != IS_OBJECT) || !instanceof_function(Z_OBJCE(EX(This)), ce)) { \ - php_error_docref(NULL, E_ERROR, "%s() cannot be called statically", get_active_function_name()); \ - return; \ - } \ - /* Exception throwing macro */ #define _DO_THROW(msg) \ zend_throw_exception(reflection_exception_ptr, msg, 0); \ @@ -110,6 +106,7 @@ PHPAPI zend_class_entry *reflection_zend_extension_ptr; typedef struct _property_reference { zend_class_entry *ce; zend_property_info prop; + zend_string *unmangled_name; } property_reference; /* Struct for parameters */ @@ -133,7 +130,6 @@ typedef enum { REF_TYPE_PARAMETER, REF_TYPE_TYPE, REF_TYPE_PROPERTY, - REF_TYPE_DYNAMIC_PROPERTY, REF_TYPE_CLASS_CONSTANT } reflection_type_t; @@ -157,42 +153,23 @@ static inline reflection_object *reflection_object_from_obj(zend_object *obj) { static zend_object_handlers reflection_object_handlers; -static zval *_default_load_entry(zval *object, char *name, size_t name_len) /* {{{ */ +static zval *_default_load_name(zval *object) /* {{{ */ { - zval *value; - - if ((value = zend_hash_str_find_ind(Z_OBJPROP_P(object), name, name_len)) == NULL) { - return NULL; - } - return value; + return zend_hash_find_ex_ind(Z_OBJPROP_P(object), ZSTR_KNOWN(ZEND_STR_NAME), 1); } /* }}} */ -static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value) /* {{{ */ +static void _default_get_name(zval *object, zval *return_value) /* {{{ */ { zval *value; - if ((value = _default_load_entry(object, name, name_len)) == NULL) { + if ((value = _default_load_name(object)) == NULL) { RETURN_FALSE; } - ZVAL_DUP(return_value, value); + ZVAL_COPY(return_value, value); } /* }}} */ -#ifdef ilia_0 -static void _default_lookup_entry(zval *object, char *name, int name_len, zval **return_value) /* {{{ */ -{ - zval **value; - - if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) { - *return_value = NULL; - } else { - *return_value = *value; - } -} -/* }}} */ -#endif - static zend_function *_copy_function(zend_function *fptr) /* {{{ */ { if (fptr @@ -210,21 +187,12 @@ static zend_function *_copy_function(zend_function *fptr) /* {{{ */ } /* }}} */ -static void _fix_closure_prototype(zend_function *fptr) /* {{{ */ -{ - /* Actually we are setting proxy function's prototype to null - * as for it, the prototype is an object not a function - * which could cause serias problems, see #74949 */ - fptr->common.prototype = NULL; -} -/* }}} */ - static void _free_function(zend_function *fptr) /* {{{ */ { if (fptr && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { - zend_string_release(fptr->internal_function.function_name); + zend_string_release_ex(fptr->internal_function.function_name, 0); zend_free_trampoline(fptr); } } @@ -253,11 +221,8 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */ _free_function(intern->ptr); break; case REF_TYPE_PROPERTY: - efree(intern->ptr); - break; - case REF_TYPE_DYNAMIC_PROPERTY: prop_reference = (property_reference*)intern->ptr; - zend_string_release(prop_reference->prop.name); + zend_string_release_ex(prop_reference->unmangled_name, 0); efree(intern->ptr); break; case REF_TYPE_GENERATOR: @@ -283,10 +248,7 @@ static HashTable *reflection_get_gc(zval *obj, zval **gc_data, int *gc_data_coun static zend_object *reflection_objects_new(zend_class_entry *class_type) /* {{{ */ { - reflection_object *intern; - - intern = ecalloc(1, sizeof(reflection_object) + zend_object_properties_size(class_type)); - intern->zo.ce = class_type; + reflection_object *intern = zend_object_alloc(sizeof(reflection_object), class_type); zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); @@ -304,7 +266,7 @@ static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{ static void _const_string(smart_str *str, char *name, zval *value, char *indent); static void _function_string(smart_str *str, zend_function *fptr, zend_class_entry *scope, char* indent); -static void _property_string(smart_str *str, zend_property_info *prop, char *prop_name, char* indent); +static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent); static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char* indent); static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char *indent); static void _extension_string(smart_str *str, zend_module_entry *module, char *indent); @@ -520,7 +482,6 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char && memcmp(ZSTR_VAL(mptr->common.function_name), ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 && (closure = zend_get_closure_invoke_method(Z_OBJ_P(obj))) != NULL) { - _fix_closure_prototype(closure); mptr = closure; } else { closure = NULL; @@ -544,7 +505,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char smart_str_append_printf(str, "%s }\n", indent); smart_str_append_printf(str, "%s}\n", indent); - zend_string_release(sub_indent); + zend_string_release_ex(sub_indent, 0); } /* }}} */ @@ -556,11 +517,15 @@ static void _const_string(smart_str *str, char *name, zval *value, char *indent) if (Z_TYPE_P(value) == IS_ARRAY) { smart_str_append_printf(str, "%s Constant [ %s %s ] { Array }\n", indent, type, name); + } else if (Z_TYPE_P(value) == IS_STRING) { + smart_str_append_printf(str, "%s Constant [ %s %s ] { %s }\n", + indent, type, name, Z_STRVAL_P(value)); } else { - zend_string *value_str = zval_get_string(value); + zend_string *tmp_value_str; + zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str); smart_str_append_printf(str, "%s Constant [ %s %s ] { %s }\n", indent, type, name, ZSTR_VAL(value_str)); - zend_string_release(value_str); + zend_tmp_string_release(tmp_value_str); } } /* }}} */ @@ -578,12 +543,13 @@ static void _class_const_string(smart_str *str, char *name, zend_class_constant smart_str_append_printf(str, "%sConstant [ %s %s %s ] { Array }\n", indent, visibility, type, name); } else { - zend_string *value_str = zval_get_string(&c->value); + zend_string *tmp_value_str; + zend_string *value_str = zval_get_tmp_string(&c->value, &tmp_value_str); smart_str_append_printf(str, "%sConstant [ %s %s %s ] { %s }\n", indent, visibility, type, name, ZSTR_VAL(value_str)); - zend_string_release(value_str); + zend_tmp_string_release(tmp_value_str); } } /* }}} */ @@ -649,7 +615,7 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_ zval zv; smart_str_appends(str, " = "); - ZVAL_DUP(&zv, RT_CONSTANT(&fptr->op_array, precv->op2)); + ZVAL_COPY(&zv, RT_CONSTANT(precv, precv->op2)); if (UNEXPECTED(zval_update_constant_ex(&zv, fptr->common.scope) == FAILURE)) { zval_ptr_dtor(&zv); return; @@ -670,9 +636,10 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_ } else if (Z_TYPE(zv) == IS_ARRAY) { smart_str_appends(str, "Array"); } else { - zend_string *zv_str = zval_get_string(&zv); + zend_string *tmp_zv_str; + zend_string *zv_str = zval_get_tmp_string(&zv, &tmp_zv_str); smart_str_append(str, zv_str); - zend_string_release(zv_str); + zend_tmp_string_release(tmp_zv_str); } zval_ptr_dtor(&zv); } @@ -741,7 +708,6 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent smart_str param_indent = {0}; zend_function *overwrites; zend_string *lc_name; - size_t lc_name_len; /* 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 @@ -765,15 +731,13 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent if (fptr->common.scope != scope) { smart_str_append_printf(str, ", inherits %s", ZSTR_VAL(fptr->common.scope->name)); } else if (fptr->common.scope->parent) { - lc_name_len = ZSTR_LEN(fptr->common.function_name); - lc_name = zend_string_alloc(lc_name_len, 0); - zend_str_tolower_copy(ZSTR_VAL(lc_name), ZSTR_VAL(fptr->common.function_name), lc_name_len); + lc_name = zend_string_tolower(fptr->common.function_name); if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { if (fptr->common.scope != overwrites->common.scope) { smart_str_append_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); } } - efree(lc_name); + zend_string_release_ex(lc_name, 0); } } if (fptr->common.prototype && fptr->common.prototype->common.scope) { @@ -857,10 +821,8 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent /* }}} */ /* {{{ _property_string */ -static void _property_string(smart_str *str, zend_property_info *prop, char *prop_name, char* indent) +static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent) { - const char *class_name; - smart_str_append_printf(str, "%sProperty [ ", indent); if (!prop) { smart_str_append_printf(str, "<dynamic> public $%s", prop_name); @@ -885,11 +847,13 @@ static void _property_string(smart_str *str, zend_property_info *prop, char *pro smart_str_appends(str, "protected "); break; } - if(prop->flags & ZEND_ACC_STATIC) { + if (prop->flags & ZEND_ACC_STATIC) { smart_str_appends(str, "static "); } - - zend_unmangle_property_name(prop->name, &class_name, (const char**)&prop_name); + 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); } @@ -962,7 +926,7 @@ static int _extension_const_string(zval *el, int num_args, va_list args, zend_ha struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int *num_classes = va_arg(args, int*); - if (constant->module_number == module->module_number) { + if (ZEND_CONSTANT_MODULE_NUMBER(constant) == module->module_number) { _const_string(str, ZSTR_VAL(constant->name), &constant->value, indent); (*num_classes)++; } @@ -1073,7 +1037,7 @@ static void _extension_string(smart_str *str, zend_module_entry *module, char *i smart_str_append_printf(str, "%s }\n", indent); } smart_str_free(&str_classes); - zend_string_release(sub_indent); + zend_string_release_ex(sub_indent, 0); } smart_str_append_printf(str, "%s}\n", indent); @@ -1127,7 +1091,7 @@ PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object) intern->ptr = ce; intern->ref_type = REF_TYPE_OTHER; intern->ce = ce; - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); } /* }}} */ @@ -1143,7 +1107,7 @@ static void reflection_extension_factory(zval *object, const char *name_str) lcname = zend_string_alloc(name_len, 0); zend_str_tolower_copy(ZSTR_VAL(lcname), name_str, name_len); module = zend_hash_find_ptr(&module_registry, lcname); - zend_string_free(lcname); + zend_string_efree(lcname); if (!module) { return; } @@ -1154,7 +1118,7 @@ static void reflection_extension_factory(zval *object, const char *name_str) intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); } /* }}} */ @@ -1189,7 +1153,7 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje Z_ADDREF_P(closure_object); ZVAL_COPY_VALUE(&intern->obj, closure_object); } - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); } /* }}} */ @@ -1231,7 +1195,7 @@ static void reflection_function_factory(zend_function *function, zval *closure_o Z_ADDREF_P(closure_object); ZVAL_COPY_VALUE(&intern->obj, closure_object); } - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); } /* }}} */ @@ -1254,29 +1218,25 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho Z_ADDREF_P(closure_object); ZVAL_COPY_VALUE(&intern->obj, closure_object); } - reflection_update_property(object, "name", &name); - reflection_update_property(object, "class", &classname); + reflection_update_property_name(object, &name); + reflection_update_property_class(object, &classname); } /* }}} */ /* {{{ reflection_property_factory */ -static void reflection_property_factory(zend_class_entry *ce, zend_property_info *prop, zval *object) +static void reflection_property_factory(zend_class_entry *ce, zend_string *name, zend_property_info *prop, zval *object) { reflection_object *intern; - zval name; + zval propname; zval classname; property_reference *reference; - const char *class_name, *prop_name; - size_t prop_name_len; - - zend_unmangle_property_name_ex(prop->name, &class_name, &prop_name, &prop_name_len); if (!(prop->flags & ZEND_ACC_PRIVATE)) { /* we have to search the class hierarchy for this (implicit) public or protected property */ zend_class_entry *tmp_ce = ce, *store_ce = ce; zend_property_info *tmp_info = NULL; - while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) == NULL) { + while (tmp_ce && (tmp_info = zend_hash_find_ptr(&tmp_ce->properties_info, name)) == NULL) { ce = tmp_ce; tmp_ce = tmp_ce->parent; } @@ -1288,7 +1248,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info } } - ZVAL_STRINGL(&name, prop_name, prop_name_len); + ZVAL_STR_COPY(&propname, name); ZVAL_STR_COPY(&classname, prop->ce->name); reflection_instantiate(reflection_property_ptr, object); @@ -1296,15 +1256,23 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info reference = (property_reference*) emalloc(sizeof(property_reference)); reference->ce = ce; reference->prop = *prop; + reference->unmangled_name = zend_string_copy(name); intern->ptr = reference; intern->ref_type = REF_TYPE_PROPERTY; intern->ce = ce; intern->ignore_visibility = 0; - reflection_update_property(object, "name", &name); - reflection_update_property(object, "class", &classname); + reflection_update_property_name(object, &propname); + reflection_update_property_class(object, &classname); } /* }}} */ +static void reflection_property_factory_str(zend_class_entry *ce, const char *name_str, size_t name_len, zend_property_info *prop, zval *object) +{ + zend_string *name = zend_string_init(name_str, name_len, 0); + reflection_property_factory(ce, name, prop, object); + zend_string_release(name); +} + /* {{{ reflection_class_constant_factory */ static void reflection_class_constant_factory(zend_class_entry *ce, zend_string *name_str, zend_class_constant *constant, zval *object) { @@ -1321,8 +1289,8 @@ static void reflection_class_constant_factory(zend_class_entry *ce, zend_string intern->ref_type = REF_TYPE_CLASS_CONSTANT; intern->ce = constant->ce; intern->ignore_visibility = 0; - reflection_update_property(object, "name", &name); - reflection_update_property(object, "class", &classname); + reflection_update_property_name(object, &name); + reflection_update_property_class(object, &classname); } /* }}} */ @@ -1366,9 +1334,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c fci.params = params; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = ce_ptr->constructor; - fcc.calling_scope = ce_ptr; fcc.called_scope = Z_OBJCE(reflector); fcc.object = Z_OBJ(reflector); @@ -1485,8 +1451,8 @@ ZEND_METHOD(reflection, export) /* Invoke the __toString() method */ ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1); - result= call_user_function_ex(NULL, object, &fname, &retval, 0, NULL, 0, NULL); - zval_dtor(&fname); + result= call_user_function(NULL, object, &fname, &retval, 0, NULL); + zval_ptr_dtor_str(&fname); if (result == FAILURE) { _DO_THROW("Invocation of method __toString() failed"); @@ -1565,11 +1531,9 @@ ZEND_METHOD(reflection_function, __construct) zval name; zval *object; zval *closure = NULL; - char *lcname, *nsname; reflection_object *intern; zend_function *fptr; - char *name_str; - size_t name_len; + zend_string *fname, *lcname; object = getThis(); intern = Z_REFLECTION_P(object); @@ -1578,30 +1542,33 @@ ZEND_METHOD(reflection_function, __construct) fptr = (zend_function*)zend_get_closure_method_def(closure); Z_ADDREF_P(closure); } else { - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { + ALLOCA_FLAG(use_heap) + + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "S", &fname) == FAILURE) { return; } - lcname = zend_str_tolower_dup(name_str, name_len); - - /* Ignore leading "\" */ - nsname = lcname; - if (lcname[0] == '\\') { - nsname = &lcname[1]; - name_len--; + if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) { + /* Ignore leading "\" */ + 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_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { - efree(lcname); + if (fptr == NULL) { zend_throw_exception_ex(reflection_exception_ptr, 0, - "Function %s() does not exist", name_str); + "Function %s() does not exist", ZSTR_VAL(fname)); return; } - efree(lcname); } ZVAL_STR_COPY(&name, fptr->common.function_name); - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); intern->ptr = fptr; intern->ref_type = REF_TYPE_FUNCTION; if (closure) { @@ -1637,7 +1604,7 @@ ZEND_METHOD(reflection_function, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); + _default_get_name(getThis(), return_value); } /* }}} */ @@ -1754,7 +1721,6 @@ ZEND_METHOD(reflection_function, isDisabled) reflection_object *intern; zend_function *fptr; - METHOD_NOTSTATIC(reflection_function_ptr); GET_REFLECTION_OBJECT_PTR(fptr); RETURN_BOOL(fptr->type == ZEND_INTERNAL_FUNCTION && fptr->internal_function.handler == zif_display_disabled_function); } @@ -1846,11 +1812,11 @@ ZEND_METHOD(reflection_function, getStaticVariables) GET_REFLECTION_OBJECT_PTR(fptr); /* Return an empty array in case no static variables exist */ - array_init(return_value); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.static_variables != NULL) { + array_init(return_value); if (GC_REFCOUNT(fptr->op_array.static_variables) > 1) { if (!(GC_FLAGS(fptr->op_array.static_variables) & IS_ARRAY_IMMUTABLE)) { - GC_REFCOUNT(fptr->op_array.static_variables)--; + GC_DELREF(fptr->op_array.static_variables); } fptr->op_array.static_variables = zend_array_dup(fptr->op_array.static_variables); } @@ -1860,6 +1826,8 @@ ZEND_METHOD(reflection_function, getStaticVariables) } } ZEND_HASH_FOREACH_END(); zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, zval_add_ref); + } else { + ZVAL_EMPTY_ARRAY(return_value); } } /* }}} */ @@ -1876,7 +1844,6 @@ ZEND_METHOD(reflection_function, invoke) reflection_object *intern; zend_function *fptr; - METHOD_NOTSTATIC(reflection_function_ptr); GET_REFLECTION_OBJECT_PTR(fptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", ¶ms, &num_args) == FAILURE) { @@ -1891,9 +1858,7 @@ ZEND_METHOD(reflection_function, invoke) fci.params = params; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = fptr; - fcc.calling_scope = zend_get_executed_scope(); fcc.called_scope = NULL; fcc.object = NULL; @@ -1933,7 +1898,6 @@ ZEND_METHOD(reflection_function, invokeArgs) zend_function *fptr; zval *param_array; - METHOD_NOTSTATIC(reflection_function_ptr); GET_REFLECTION_OBJECT_PTR(fptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", ¶m_array) == FAILURE) { @@ -1957,9 +1921,7 @@ ZEND_METHOD(reflection_function, invokeArgs) fci.params = params; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = fptr; - fcc.calling_scope = zend_get_executed_scope(); fcc.called_scope = NULL; fcc.object = NULL; @@ -1997,7 +1959,6 @@ ZEND_METHOD(reflection_function, returnsReference) reflection_object *intern; zend_function *fptr; - METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); RETURN_BOOL((fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0); @@ -2012,7 +1973,6 @@ ZEND_METHOD(reflection_function, getNumberOfParameters) zend_function *fptr; uint32_t num_args; - METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); num_args = fptr->common.num_args; @@ -2031,7 +1991,6 @@ ZEND_METHOD(reflection_function, getNumberOfRequiredParameters) reflection_object *intern; zend_function *fptr; - METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); RETURN_LONG(fptr->common.required_num_args); @@ -2047,7 +2006,6 @@ ZEND_METHOD(reflection_function, getParameters) uint32_t i, num_args; struct _zend_arg_info *arg_info; - METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); arg_info= fptr->common.arg_info; @@ -2056,6 +2014,11 @@ ZEND_METHOD(reflection_function, getParameters) num_args++; } + if (!num_args) { + ZVAL_EMPTY_ARRAY(return_value); + return; + } + array_init(return_value); for (i = 0; i < num_args; i++) { zval parameter; @@ -2083,7 +2046,6 @@ ZEND_METHOD(reflection_function, getExtension) zend_function *fptr; zend_internal_function *internal; - METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type != ZEND_INTERNAL_FUNCTION) { @@ -2107,7 +2069,6 @@ ZEND_METHOD(reflection_function, getExtensionName) zend_function *fptr; zend_internal_function *internal; - METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type != ZEND_INTERNAL_FUNCTION) { @@ -2237,7 +2198,7 @@ ZEND_METHOD(reflection_generator, getFunction) if (ex->func->common.fn_flags & ZEND_ACC_CLOSURE) { zval closure; - ZVAL_OBJ(&closure, (zend_object *) ex->func->common.prototype); + ZVAL_OBJ(&closure, ZEND_CLOSURE_OBJECT(ex->func)); reflection_function_factory(ex->func, &closure, return_value); } else if (ex->func->op_array.scope) { reflection_method_factory(ex->func->op_array.scope, ex->func, NULL, return_value); @@ -2281,7 +2242,7 @@ ZEND_METHOD(reflection_generator, getExecutingGenerator) REFLECTION_CHECK_VALID_GENERATOR(ex) current = zend_generator_get_current(generator); - ++GC_REFCOUNT(¤t->std); + GC_ADDREF(¤t->std); ZVAL_OBJ(return_value, (zend_object *) current); } @@ -2371,7 +2332,6 @@ ZEND_METHOD(reflection_parameter, __construct) { /* nothing to do. don't set is_closure since is the invoke handler, not the closure itself */ - _fix_closure_prototype(fptr); } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, lcname, lcname_len)) == NULL) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0, @@ -2413,7 +2373,7 @@ ZEND_METHOD(reflection_parameter, __construct) if (position < 0 || (uint32_t)position >= num_args) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - zend_string_release(fptr->common.function_name); + zend_string_release_ex(fptr->common.function_name, 0); } zend_free_trampoline(fptr); } @@ -2452,7 +2412,7 @@ ZEND_METHOD(reflection_parameter, __construct) if (position == -1) { if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - zend_string_release(fptr->common.function_name); + zend_string_release_ex(fptr->common.function_name, 0); } zend_free_trampoline(fptr); } @@ -2474,7 +2434,7 @@ ZEND_METHOD(reflection_parameter, __construct) } else { ZVAL_NULL(&name); } - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); ref = (parameter_reference*) emalloc(sizeof(parameter_reference)); ref->arg_info = &arg_info[position]; @@ -2516,7 +2476,7 @@ ZEND_METHOD(reflection_parameter, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); + _default_get_name(getThis(), return_value); } /* }}} */ @@ -2815,8 +2775,8 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) return; } - ZVAL_DUP(return_value, RT_CONSTANT(¶m->fptr->op_array, precv->op2)); - if (Z_CONSTANT_P(return_value)) { + ZVAL_COPY(return_value, RT_CONSTANT(precv, precv->op2)); + if (Z_TYPE_P(return_value) == IS_CONSTANT_AST) { zval_update_constant_ex(return_value, param->fptr->common.scope); } } @@ -2839,8 +2799,13 @@ ZEND_METHOD(reflection_parameter, isDefaultValueConstant) } precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); - if (precv && Z_TYPE_P(RT_CONSTANT(¶m->fptr->op_array, precv->op2)) == IS_CONSTANT) { - RETURN_TRUE; + if (precv && Z_TYPE_P(RT_CONSTANT(precv, precv->op2)) == IS_CONSTANT_AST) { + zend_ast *ast = Z_ASTVAL_P(RT_CONSTANT(precv, precv->op2)); + + if (ast->kind == ZEND_AST_CONSTANT + || ast->kind == ZEND_AST_CONSTANT_CLASS) { + RETURN_TRUE; + } } RETURN_FALSE; @@ -2864,8 +2829,14 @@ ZEND_METHOD(reflection_parameter, getDefaultValueConstantName) } precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); - if (precv && Z_TYPE_P(RT_CONSTANT(¶m->fptr->op_array, precv->op2)) == IS_CONSTANT) { - RETURN_STR_COPY(Z_STR_P(RT_CONSTANT(¶m->fptr->op_array, precv->op2))); + if (precv && Z_TYPE_P(RT_CONSTANT(precv, precv->op2)) == IS_CONSTANT_AST) { + zend_ast *ast = Z_ASTVAL_P(RT_CONSTANT(precv, precv->op2)); + + if (ast->kind == ZEND_AST_CONSTANT) { + RETURN_STR_COPY(zend_ast_get_constant_name(ast)); + } else if (ast->kind == ZEND_AST_CONSTANT_CLASS) { + RETURN_STRINGL("__CLASS__", sizeof("__CLASS__")-1); + } } } /* }}} */ @@ -2922,17 +2893,9 @@ ZEND_METHOD(reflection_type, isBuiltin) static zend_string *reflection_type_name(type_reference *param) { if (ZEND_TYPE_IS_CLASS(param->arg_info->type)) { return zend_string_copy(ZEND_TYPE_NAME(param->arg_info->type)); - } - switch (ZEND_TYPE_CODE(param->arg_info->type)) { - /* keep this for BC, bool vs boolean, int vs integer */ - case _IS_BOOL: return zend_string_init("bool", sizeof("bool") - 1, 0); - case IS_LONG: return zend_string_init("int", sizeof("int") - 1, 0); - /* use zend API for other types */ - default: - { - char *name = zend_get_type_by_const(ZEND_TYPE_CODE(param->arg_info->type)); - return zend_string_init(name, strlen(name), 0); - } + } else { + char *name = zend_get_type_by_const(ZEND_TYPE_CODE(param->arg_info->type)); + return zend_string_init(name, strlen(name), 0); } } /* }}} */ @@ -3025,7 +2988,7 @@ ZEND_METHOD(reflection_method, __construct) "Class %s does not exist", Z_STRVAL_P(classname)); } if (classname == &ztmp) { - zval_dtor(&ztmp); + zval_ptr_dtor_str(&ztmp); } return; } @@ -3037,14 +3000,14 @@ ZEND_METHOD(reflection_method, __construct) default: if (classname == &ztmp) { - zval_dtor(&ztmp); + zval_ptr_dtor_str(&ztmp); } _DO_THROW("The parameter class is expected to be either a string or an object"); /* returns out of this function */ } if (classname == &ztmp) { - zval_dtor(&ztmp); + zval_ptr_dtor_str(&ztmp); } lcname = zend_str_tolower_dup(name_str, name_len); @@ -3054,7 +3017,6 @@ ZEND_METHOD(reflection_method, __construct) && (mptr = zend_get_closure_invoke_method(Z_OBJ_P(orig_obj))) != NULL) { /* do nothing, mptr already set */ - _fix_closure_prototype(mptr); } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lcname, name_len)) == NULL) { efree(lcname); zend_throw_exception_ex(reflection_exception_ptr, 0, @@ -3064,9 +3026,9 @@ ZEND_METHOD(reflection_method, __construct) efree(lcname); ZVAL_STR_COPY(&name, mptr->common.scope->name); - reflection_update_property(object, "class", &name); + reflection_update_property_class(object, &name); ZVAL_STR_COPY(&name, mptr->common.function_name); - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); intern->ptr = mptr; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; @@ -3098,7 +3060,6 @@ ZEND_METHOD(reflection_method, getClosure) zval *obj; zend_function *mptr; - METHOD_NOTSTATIC(reflection_method_ptr); GET_REFLECTION_OBJECT_PTR(mptr); if (mptr->common.fn_flags & ZEND_ACC_STATIC) { @@ -3138,25 +3099,21 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic) zend_class_entry *obj_ce; zval *param_array; - METHOD_NOTSTATIC(reflection_method_ptr); - GET_REFLECTION_OBJECT_PTR(mptr); - if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) - || (mptr->common.fn_flags & ZEND_ACC_ABSTRACT)) - && intern->ignore_visibility == 0) - { - if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Trying to invoke abstract method %s::%s()", - ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); - } else { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Trying to invoke %s method %s::%s() from scope %s", - mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", - ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name), - ZSTR_VAL(Z_OBJCE_P(getThis())->name)); - } + if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Trying to invoke abstract method %s::%s()", + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); + return; + } + + if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Trying to invoke %s method %s::%s() from scope %s", + mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name), + ZSTR_VAL(Z_OBJCE_P(getThis())->name)); return; } @@ -3215,9 +3172,7 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic) fci.params = params; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = mptr; - fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; fcc.object = object ? Z_OBJ_P(object) : NULL; @@ -3350,7 +3305,7 @@ ZEND_METHOD(reflection_function, inNamespace) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_name(getThis())) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3373,7 +3328,7 @@ ZEND_METHOD(reflection_function, getNamespaceName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_name(getThis())) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3396,7 +3351,7 @@ ZEND_METHOD(reflection_function, getShortName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_name(getThis())) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -3405,8 +3360,7 @@ ZEND_METHOD(reflection_function, getShortName) { RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } - ZVAL_DEREF(name); - ZVAL_COPY(return_value, name); + ZVAL_COPY_DEREF(return_value, name); } /* }}} */ @@ -3506,7 +3460,6 @@ ZEND_METHOD(reflection_method, getDeclaringClass) reflection_object *intern; zend_function *mptr; - METHOD_NOTSTATIC(reflection_method_ptr); GET_REFLECTION_OBJECT_PTR(mptr); if (zend_parse_parameters_none() == FAILURE) { @@ -3524,7 +3477,6 @@ ZEND_METHOD(reflection_method, getPrototype) reflection_object *intern; zend_function *mptr; - METHOD_NOTSTATIC(reflection_method_ptr); GET_REFLECTION_OBJECT_PTR(mptr); if (zend_parse_parameters_none() == FAILURE) { @@ -3606,8 +3558,8 @@ ZEND_METHOD(reflection_class_constant, __construct) intern->ref_type = REF_TYPE_CLASS_CONSTANT; intern->ce = constant->ce; intern->ignore_visibility = 0; - reflection_update_property(object, "name", &name); - reflection_update_property(object, "class", &cname); + reflection_update_property_name(object, &name); + reflection_update_property_class(object, &cname); } /* }}} */ @@ -3624,7 +3576,7 @@ ZEND_METHOD(reflection_class_constant, __toString) return; } GET_REFLECTION_OBJECT_PTR(ref); - _default_get_entry(getThis(), "name", sizeof("name")-1, &name); + _default_get_name(getThis(), &name); _class_const_string(&str, Z_STRVAL(name), ref, ""); zval_ptr_dtor(&name); RETURN_STR(smart_str_extract(&str)); @@ -3638,7 +3590,7 @@ ZEND_METHOD(reflection_class_constant, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); + _default_get_name(getThis(), return_value); } /* }}} */ @@ -3707,8 +3659,8 @@ ZEND_METHOD(reflection_class_constant, getValue) } GET_REFLECTION_OBJECT_PTR(ref); - ZVAL_DUP(return_value, &ref->value); - if (Z_CONSTANT_P(return_value)) { + ZVAL_COPY_OR_DUP(return_value, &ref->value); + if (Z_TYPE_P(return_value) == IS_CONSTANT_AST) { zval_update_constant_ex(return_value, ref->ce); } } @@ -3770,7 +3722,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &argument) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &argument) == FAILURE) { return; } } @@ -3780,11 +3732,10 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob if (Z_TYPE_P(argument) == IS_OBJECT) { ZVAL_STR_COPY(&classname, Z_OBJCE_P(argument)->name); - reflection_update_property(object, "name", &classname); + reflection_update_property_name(object, &classname); intern->ptr = Z_OBJCE_P(argument); if (is_object) { - ZVAL_COPY_VALUE(&intern->obj, argument); - zval_add_ref(argument); + ZVAL_COPY(&intern->obj, argument); } } else { convert_to_string_ex(argument); @@ -3796,7 +3747,7 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob } ZVAL_STR_COPY(&classname, ce->name); - reflection_update_property(object, "name", &classname); + reflection_update_property_name(object, &classname); intern->ptr = ce; } @@ -3831,6 +3782,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value prop = NULL; if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) { prop = &ce->default_static_members_table[prop_info->offset]; + ZVAL_DEINDIRECT(prop); } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) { prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)]; } @@ -3840,11 +3792,11 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value /* copy: enforce read only access */ ZVAL_DEREF(prop); - ZVAL_DUP(&prop_copy, prop); + ZVAL_COPY_OR_DUP(&prop_copy, prop); /* this is necessary to make it able to work with default array * properties, returned to user */ - if (Z_CONSTANT(prop_copy)) { + if (Z_TYPE(prop_copy) == IS_CONSTANT_AST) { if (UNEXPECTED(zval_update_constant_ex(&prop_copy, NULL) != SUCCESS)) { return; } @@ -3905,8 +3857,7 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue) } return; } else { - ZVAL_DEREF(prop); - ZVAL_COPY(return_value, prop); + ZVAL_COPY_DEREF(return_value, prop); } } /* }}} */ @@ -3985,7 +3936,7 @@ ZEND_METHOD(reflection_class, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); + _default_get_name(getThis(), return_value); } /* }}} */ @@ -4135,7 +4086,6 @@ ZEND_METHOD(reflection_class, hasMethod) char *name, *lc_name; size_t name_len; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { return; } @@ -4165,7 +4115,6 @@ ZEND_METHOD(reflection_class, getMethod) char *name, *lc_name; size_t name_len; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { return; } @@ -4178,7 +4127,6 @@ ZEND_METHOD(reflection_class, getMethod) { /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself */ - _fix_closure_prototype(mptr); reflection_method_factory(ce, mptr, NULL, return_value); efree(lc_name); } else if (ce == zend_ce_closure && Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) @@ -4186,9 +4134,8 @@ ZEND_METHOD(reflection_class, getMethod) && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(Z_OBJ(obj_tmp))) != NULL) { /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself */ - _fix_closure_prototype(mptr); reflection_method_factory(ce, mptr, NULL, return_value); - zval_dtor(&obj_tmp); + zval_ptr_dtor(&obj_tmp); efree(lc_name); } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lc_name, name_len)) != NULL) { reflection_method_factory(ce, mptr, NULL, return_value); @@ -4235,7 +4182,6 @@ ZEND_METHOD(reflection_class, getMethods) zend_long filter = 0; zend_bool filter_is_null = 1; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) { return; } @@ -4261,7 +4207,6 @@ ZEND_METHOD(reflection_class, getMethods) } zend_function *closure = zend_get_closure_invoke_method(obj); if (closure) { - _fix_closure_prototype(closure); _addmethod(closure, ce, return_value, filter); } if (!has_obj) { @@ -4281,7 +4226,6 @@ ZEND_METHOD(reflection_class, hasProperty) zend_string *name; zval property; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } @@ -4317,7 +4261,6 @@ ZEND_METHOD(reflection_class, getProperty) char *tmp, *str_name; size_t classname_len, str_name_len; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } @@ -4325,7 +4268,7 @@ ZEND_METHOD(reflection_class, getProperty) GET_REFLECTION_OBJECT_PTR(ce); if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) { if ((property_info->flags & ZEND_ACC_SHADOW) == 0) { - reflection_property_factory(ce, property_info, return_value); + reflection_property_factory(ce, name, property_info, return_value); return; } } else if (Z_TYPE(intern->obj) != IS_UNDEF) { @@ -4333,18 +4276,15 @@ ZEND_METHOD(reflection_class, getProperty) if (zend_hash_exists(Z_OBJ_HT(intern->obj)->get_properties(&intern->obj), name)) { zend_property_info property_info_tmp; property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC; - property_info_tmp.name = zend_string_copy(name); + property_info_tmp.name = name; property_info_tmp.doc_comment = NULL; property_info_tmp.ce = ce; - reflection_property_factory(ce, &property_info_tmp, return_value); - intern = Z_REFLECTION_P(return_value); - intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY; + reflection_property_factory(ce, name, &property_info_tmp, return_value); return; } } str_name = ZSTR_VAL(name); - str_name_len = ZSTR_LEN(name); if ((tmp = strstr(ZSTR_VAL(name), "::")) != NULL) { classname_len = tmp - ZSTR_VAL(name); classname = zend_string_alloc(classname_len, 0); @@ -4358,10 +4298,10 @@ ZEND_METHOD(reflection_class, getProperty) if (!EG(exception)) { zend_throw_exception_ex(reflection_exception_ptr, -1, "Class %s does not exist", ZSTR_VAL(classname)); } - zend_string_release(classname); + zend_string_release_ex(classname, 0); return; } - zend_string_release(classname); + zend_string_release_ex(classname, 0); if (!instanceof_function(ce, ce2)) { zend_throw_exception_ex(reflection_exception_ptr, -1, "Fully qualified property name %s::%s does not specify a base class of %s", ZSTR_VAL(ce2->name), str_name, ZSTR_VAL(ce->name)); @@ -4370,7 +4310,7 @@ ZEND_METHOD(reflection_class, getProperty) ce = ce2; if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, str_name, str_name_len)) != NULL && (property_info->flags & ZEND_ACC_SHADOW) == 0) { - reflection_property_factory(ce, property_info, return_value); + reflection_property_factory_str(ce, str_name, str_name_len, property_info, return_value); return; } } @@ -4393,7 +4333,10 @@ static int _addproperty(zval *el, int num_args, va_list args, zend_hash_key *has } if (pptr->flags & filter) { - reflection_property_factory(ce, pptr, &property); + const char *class_name, *prop_name; + size_t prop_name_len; + zend_unmangle_property_name_ex(pptr->name, &class_name, &prop_name, &prop_name_len); + reflection_property_factory_str(ce, prop_name, prop_name_len, pptr, &property); add_next_index_zval(retval, &property); } return 0; @@ -4426,7 +4369,7 @@ static int _adddynproperty(zval *ptr, int num_args, va_list args, zend_hash_key property_info.name = hash_key->key; property_info.ce = ce; property_info.offset = -1; - reflection_property_factory(ce, &property_info, &property); + reflection_property_factory(ce, hash_key->key, &property_info, &property); add_next_index_zval(retval, &property); } return 0; @@ -4442,7 +4385,6 @@ ZEND_METHOD(reflection_class, getProperties) zend_long filter = 0; zend_bool filter_is_null = 1; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &filter, &filter_is_null) == FAILURE) { return; } @@ -4471,7 +4413,6 @@ ZEND_METHOD(reflection_class, hasConstant) zend_class_entry *ce; zend_string *name; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } @@ -4493,7 +4434,7 @@ ZEND_METHOD(reflection_class, getConstants) zend_class_entry *ce; zend_string *key; zend_class_constant *c; - zval *val; + zval val; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4505,8 +4446,8 @@ ZEND_METHOD(reflection_class, getConstants) zend_array_destroy(Z_ARRVAL_P(return_value)); RETURN_NULL(); } - val = zend_hash_add_new(Z_ARRVAL_P(return_value), key, &c->value); - Z_TRY_ADDREF_P(val); + ZVAL_COPY_OR_DUP(&val, &c->value); + zend_hash_add_new(Z_ARRVAL_P(return_value), key, &val); } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -4542,7 +4483,6 @@ ZEND_METHOD(reflection_class, getConstant) zend_class_constant *c; zend_string *name; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } @@ -4556,7 +4496,7 @@ ZEND_METHOD(reflection_class, getConstant) if ((c = zend_hash_find_ptr(&ce->constants_table, name)) == NULL) { RETURN_FALSE; } - ZVAL_DUP(return_value, &c->value); + ZVAL_COPY_OR_DUP(return_value, &c->value); } /* }}} */ @@ -4649,7 +4589,7 @@ ZEND_METHOD(reflection_class, isCloneable) return; } RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL); - zval_dtor(&obj); + zval_ptr_dtor(&obj); } } } @@ -4713,7 +4653,6 @@ ZEND_METHOD(reflection_class, isInstance) zend_class_entry *ce; zval *object; - METHOD_NOTSTATIC(reflection_class_ptr); if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &object) == FAILURE) { return; } @@ -4731,7 +4670,6 @@ ZEND_METHOD(reflection_class, newInstance) zend_class_entry *ce, *old_scope; zend_function *constructor; - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if (UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) { @@ -4752,17 +4690,17 @@ ZEND_METHOD(reflection_class, newInstance) 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_dtor(return_value); + zval_ptr_dtor(return_value); RETURN_NULL(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", ¶ms, &num_args) == FAILURE) { - zval_dtor(return_value); + zval_ptr_dtor(return_value); RETURN_FALSE; } for (i = 0; i < num_args; i++) { - if (Z_REFCOUNTED(params[i])) Z_ADDREF(params[i]); + Z_TRY_ADDREF(params[i]); } fci.size = sizeof(fci); @@ -4773,9 +4711,7 @@ ZEND_METHOD(reflection_class, newInstance) fci.params = params; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = constructor; - fcc.calling_scope = zend_get_executed_scope(); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object = Z_OBJ_P(return_value); @@ -4790,7 +4726,7 @@ ZEND_METHOD(reflection_class, newInstance) } if (ret == FAILURE) { php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name)); - zval_dtor(return_value); + zval_ptr_dtor(return_value); RETURN_NULL(); } } else if (ZEND_NUM_ARGS()) { @@ -4806,7 +4742,6 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) reflection_object *intern; zend_class_entry *ce; - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL) { @@ -4829,8 +4764,6 @@ ZEND_METHOD(reflection_class, newInstanceArgs) HashTable *args; zend_function *constructor; - - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|h", &args) == FAILURE) { @@ -4858,7 +4791,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) 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_dtor(return_value); + zval_ptr_dtor(return_value); RETURN_NULL(); } @@ -4879,9 +4812,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fci.params = params; fci.no_separation = 1; - fcc.initialized = 1; fcc.function_handler = constructor; - fcc.calling_scope = zend_get_executed_scope(); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object = Z_OBJ_P(return_value); @@ -4900,7 +4831,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (ret == FAILURE) { zval_ptr_dtor(&retval); php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name)); - zval_dtor(return_value); + zval_ptr_dtor(return_value); RETURN_NULL(); } } else if (argc) { @@ -4921,17 +4852,17 @@ ZEND_METHOD(reflection_class, getInterfaces) } GET_REFLECTION_OBJECT_PTR(ce); - /* Return an empty array if this class implements no interfaces */ - array_init(return_value); - if (ce->num_interfaces) { uint32_t i; + array_init(return_value); for (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); } + } else { + ZVAL_EMPTY_ARRAY(return_value); } } /* }}} */ @@ -4949,7 +4880,12 @@ ZEND_METHOD(reflection_class, getInterfaceNames) } GET_REFLECTION_OBJECT_PTR(ce); - /* Return an empty array if this class implements no interfaces */ + if (!ce->num_interfaces) { + /* Return an empty array if this class implements no interfaces */ + ZVAL_EMPTY_ARRAY(return_value); + return; + } + array_init(return_value); for (i=0; i < ce->num_interfaces; i++) { @@ -4971,6 +4907,11 @@ ZEND_METHOD(reflection_class, getTraits) } GET_REFLECTION_OBJECT_PTR(ce); + if (!ce->num_traits) { + ZVAL_EMPTY_ARRAY(return_value); + return; + } + array_init(return_value); for (i=0; i < ce->num_traits; i++) { @@ -4994,6 +4935,11 @@ ZEND_METHOD(reflection_class, getTraitNames) } GET_REFLECTION_OBJECT_PTR(ce); + if (!ce->num_traits) { + ZVAL_EMPTY_ARRAY(return_value); + return; + } + array_init(return_value); for (i=0; i < ce->num_traits; i++) { @@ -5002,7 +4948,7 @@ ZEND_METHOD(reflection_class, getTraitNames) } /* }}} */ -/* {{{ proto public arra ReflectionClass::getTraitaliases() +/* {{{ proto public array ReflectionClass::getTraitAliases() Returns an array of trait aliases */ ZEND_METHOD(reflection_class, getTraitAliases) { @@ -5014,22 +4960,25 @@ ZEND_METHOD(reflection_class, getTraitAliases) } GET_REFLECTION_OBJECT_PTR(ce); - array_init(return_value); if (ce->trait_aliases) { uint32_t i = 0; + + array_init(return_value); while (ce->trait_aliases[i]) { zend_string *mname; - zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method; + zend_trait_method_reference *cur_ref = &ce->trait_aliases[i]->trait_method; if (ce->trait_aliases[i]->alias) { - mname = zend_string_alloc(ZSTR_LEN(cur_ref->ce->name) + ZSTR_LEN(cur_ref->method_name) + 2, 0); - snprintf(ZSTR_VAL(mname), ZSTR_LEN(mname) + 1, "%s::%s", ZSTR_VAL(cur_ref->ce->name), ZSTR_VAL(cur_ref->method_name)); + mname = zend_string_alloc(ZSTR_LEN(cur_ref->class_name) + ZSTR_LEN(cur_ref->method_name) + 2, 0); + snprintf(ZSTR_VAL(mname), ZSTR_LEN(mname) + 1, "%s::%s", ZSTR_VAL(cur_ref->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); } i++; } + } else { + ZVAL_EMPTY_ARRAY(return_value); } } /* }}} */ @@ -5062,7 +5011,6 @@ ZEND_METHOD(reflection_class, isSubclassOf) zend_class_entry *ce, *class_ce; zval *class_name; - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &class_name) == FAILURE) { @@ -5106,7 +5054,6 @@ ZEND_METHOD(reflection_class, implementsInterface) zend_class_entry *ce, *interface_ce; zval *interface; - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &interface) == FAILURE) { @@ -5158,7 +5105,6 @@ ZEND_METHOD(reflection_class, isIterable) return; } - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | @@ -5181,7 +5127,6 @@ ZEND_METHOD(reflection_class, getExtension) return; } - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) { @@ -5201,7 +5146,6 @@ ZEND_METHOD(reflection_class, getExtensionName) return; } - METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) { @@ -5222,7 +5166,7 @@ ZEND_METHOD(reflection_class, inNamespace) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_name(getThis())) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -5245,7 +5189,7 @@ ZEND_METHOD(reflection_class, getNamespaceName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_name(getThis())) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -5268,7 +5212,7 @@ ZEND_METHOD(reflection_class, getShortName) if (zend_parse_parameters_none() == FAILURE) { return; } - if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { + if ((name = _default_load_name(getThis())) == NULL) { RETURN_FALSE; } if (Z_TYPE_P(name) == IS_STRING @@ -5277,8 +5221,7 @@ ZEND_METHOD(reflection_class, getShortName) { RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } - ZVAL_DEREF(name); - ZVAL_COPY(return_value, name); + ZVAL_COPY_DEREF(return_value, name); } /* }}} */ @@ -5319,8 +5262,7 @@ ZEND_METHOD(reflection_class_constant, export) ZEND_METHOD(reflection_property, __construct) { zval propname, cname, *classname; - char *name_str; - size_t name_len; + zend_string *name; int dynam_prop = 0; zval *object; reflection_object *intern; @@ -5328,7 +5270,7 @@ ZEND_METHOD(reflection_property, __construct) zend_property_info *property_info = NULL; property_reference *reference; - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zS", &classname, &name) == FAILURE) { return; } @@ -5354,15 +5296,15 @@ ZEND_METHOD(reflection_property, __construct) /* returns out of this function */ } - if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, name_str, name_len)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) { + if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) { /* Check for dynamic properties */ if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) { - if (zend_hash_str_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name_str, name_len)) { + if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name)) { dynam_prop = 1; } } if (dynam_prop == 0) { - zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), name_str); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name)); return; } } @@ -5372,7 +5314,7 @@ ZEND_METHOD(reflection_property, __construct) zend_class_entry *tmp_ce = ce; zend_property_info *tmp_info; - while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, name_str, name_len)) == NULL) { + while (tmp_ce && (tmp_info = zend_hash_find_ptr(&tmp_ce->properties_info, name)) == NULL) { ce = tmp_ce; property_info = tmp_info; tmp_ce = tmp_ce->parent; @@ -5380,28 +5322,26 @@ ZEND_METHOD(reflection_property, __construct) } if (dynam_prop == 0) { - const char *class_name, *prop_name; - size_t prop_name_len; - zend_unmangle_property_name_ex(property_info->name, &class_name, &prop_name, &prop_name_len); ZVAL_STR_COPY(&cname, property_info->ce->name); - ZVAL_STRINGL(&propname, prop_name, prop_name_len); } else { ZVAL_STR_COPY(&cname, ce->name); - ZVAL_STRINGL(&propname, name_str, name_len); } - reflection_update_property(object, "class", &cname); - reflection_update_property(object, "name", &propname); + reflection_update_property_class(object, &cname); + + ZVAL_STR_COPY(&propname, name); + reflection_update_property_name(object, &propname); reference = (property_reference*) emalloc(sizeof(property_reference)); if (dynam_prop) { reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC; - reference->prop.name = Z_STR(propname); + reference->prop.name = name; reference->prop.doc_comment = NULL; reference->prop.ce = ce; } else { reference->prop = *property_info; } reference->ce = ce; + reference->unmangled_name = zend_string_copy(name); intern->ptr = reference; intern->ref_type = REF_TYPE_PROPERTY; intern->ce = ce; @@ -5421,7 +5361,7 @@ ZEND_METHOD(reflection_property, __toString) return; } GET_REFLECTION_OBJECT_PTR(ref); - _property_string(&str, &ref->prop, NULL, ""); + _property_string(&str, &ref->prop, ZSTR_VAL(ref->unmangled_name), ""); RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -5433,7 +5373,7 @@ ZEND_METHOD(reflection_property, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); + _default_get_name(getThis(), return_value); } /* }}} */ @@ -5516,30 +5456,21 @@ ZEND_METHOD(reflection_property, getValue) zval *object, *name; zval *member_p = NULL; - METHOD_NOTSTATIC(reflection_property_ptr); GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) { - name = _default_load_entry(getThis(), "name", sizeof("name")-1); + name = _default_load_name(getThis()); zend_throw_exception_ex(reflection_exception_ptr, 0, - "Cannot access non-public member %s::%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name)); + "Cannot access non-public member %s::$%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name)); return; } - if ((ref->prop.flags & ZEND_ACC_STATIC)) { - if (UNEXPECTED(zend_update_class_constants(intern->ce) != SUCCESS)) { - return; - } - if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) { - zend_throw_error(NULL, "Internal error: Could not find the property %s::%s", ZSTR_VAL(intern->ce->name), ZSTR_VAL(ref->prop.name)); - return; + if (ref->prop.flags & ZEND_ACC_STATIC) { + member_p = zend_read_static_property_ex(ref->ce, ref->unmangled_name, 0); + if (member_p) { + ZVAL_COPY_DEREF(return_value, member_p); } - member_p = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]; - ZVAL_DEREF(member_p); - ZVAL_COPY(return_value, member_p); } else { - const char *class_name, *prop_name; - size_t prop_name_len; zval rv; if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &object) == FAILURE) { @@ -5551,11 +5482,9 @@ ZEND_METHOD(reflection_property, getValue) /* Returns from this function */ } - zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len); - member_p = zend_read_property(ref->ce, object, prop_name, prop_name_len, 0, &rv); + member_p = zend_read_property_ex(ref->ce, object, ref->unmangled_name, 0, &rv); if (member_p != &rv) { - ZVAL_DEREF(member_p); - ZVAL_COPY(return_value, member_p); + ZVAL_COPY_DEREF(return_value, member_p); } else { if (Z_ISREF_P(member_p)) { zend_unwrap_reference(member_p); @@ -5572,58 +5501,33 @@ ZEND_METHOD(reflection_property, setValue) { reflection_object *intern; property_reference *ref; - zval *variable_ptr; zval *object, *name; zval *value; zval *tmp; - METHOD_NOTSTATIC(reflection_property_ptr); GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { - name = _default_load_entry(getThis(), "name", sizeof("name")-1); + name = _default_load_name(getThis()); zend_throw_exception_ex(reflection_exception_ptr, 0, - "Cannot access non-public member %s::%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name)); + "Cannot access non-public member %s::$%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name)); return; } - if ((ref->prop.flags & ZEND_ACC_STATIC)) { + if (ref->prop.flags & ZEND_ACC_STATIC) { if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z", &value) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &tmp, &value) == FAILURE) { return; } } - if (UNEXPECTED(zend_update_class_constants(intern->ce) != SUCCESS)) { - return; - } - - if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) { - zend_throw_error(NULL, "Internal error: Could not find the property %s::%s", ZSTR_VAL(intern->ce->name), ZSTR_VAL(ref->prop.name)); - return; - } - variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]; - if (variable_ptr != value) { - zval garbage; - - ZVAL_DEREF(variable_ptr); - ZVAL_DEREF(value); - ZVAL_COPY_VALUE(&garbage, variable_ptr); - - ZVAL_COPY(variable_ptr, value); - - zval_ptr_dtor(&garbage); - } + zend_update_static_property_ex(ref->ce, ref->unmangled_name, value); } else { - const char *class_name, *prop_name; - size_t prop_name_len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "oz", &object, &value) == FAILURE) { return; } - zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len); - zend_update_property(ref->ce, object, prop_name, prop_name_len, value); + zend_update_property_ex(ref->ce, object, ref->unmangled_name, value); } } /* }}} */ @@ -5636,20 +5540,14 @@ ZEND_METHOD(reflection_property, getDeclaringClass) property_reference *ref; zend_class_entry *tmp_ce, *ce; zend_property_info *tmp_info; - const char *prop_name, *class_name; - size_t prop_name_len; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ref); - if (zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len) != SUCCESS) { - RETURN_FALSE; - } - ce = tmp_ce = ref->ce; - while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) != NULL) { + while (tmp_ce && (tmp_info = zend_hash_find_ptr(&tmp_ce->properties_info, ref->unmangled_name)) != NULL) { if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) { /* it's a private property, so it can't be inherited */ break; @@ -5738,7 +5636,7 @@ ZEND_METHOD(reflection_extension, __construct) } free_alloca(lcname, use_heap); ZVAL_STRING(&name, module->name); - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; @@ -5769,7 +5667,7 @@ ZEND_METHOD(reflection_extension, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); + _default_get_name(getThis(), return_value); } /* }}} */ @@ -5826,8 +5724,8 @@ static int _addconstant(zval *el, int num_args, va_list args, zend_hash_key *has zval *retval = va_arg(args, zval*); int number = va_arg(args, int); - if (number == constant->module_number) { - ZVAL_DUP(&const_val, &constant->value); + if (number == ZEND_CONSTANT_MODULE_NUMBER(constant)) { + ZVAL_COPY_OR_DUP(&const_val, &constant->value); zend_hash_update(Z_ARRVAL_P(retval), constant->name, &const_val); } return 0; @@ -5965,15 +5863,15 @@ ZEND_METHOD(reflection_extension, getDependencies) } GET_REFLECTION_OBJECT_PTR(module); - array_init(return_value); - dep = module->deps; if (!dep) { + ZVAL_EMPTY_ARRAY(return_value); return; } + array_init(return_value); while(dep->name) { zend_string *relation; char *rel_type; @@ -6100,7 +5998,7 @@ ZEND_METHOD(reflection_zend_extension, __construct) return; } ZVAL_STRING(&name, extension->name); - reflection_update_property(object, "name", &name); + reflection_update_property_name(object, &name); intern->ptr = extension; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; @@ -6698,12 +6596,10 @@ static const zend_function_entry reflection_zend_extension_functions[] = { }; /* }}} */ -const zend_function_entry reflection_ext_functions[] = { /* {{{ */ +static const zend_function_entry reflection_ext_functions[] = { /* {{{ */ PHP_FE_END }; /* }}} */ -static zend_object_handlers *zend_std_obj_handlers; - /* {{{ _reflection_write_property */ static void _reflection_write_property(zval *object, zval *member, zval *value, void **cache_slot) { @@ -6717,7 +6613,7 @@ static void _reflection_write_property(zval *object, zval *member, zval *value, } else { - zend_std_obj_handlers->write_property(object, member, value, cache_slot); + zend_std_write_property(object, member, value, cache_slot); } } /* }}} */ @@ -6726,8 +6622,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ { zend_class_entry _reflection_entry; - zend_std_obj_handlers = zend_get_std_object_handlers(); - memcpy(&reflection_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); + memcpy(&reflection_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); reflection_object_handlers.offset = XtOffsetOf(reflection_object, zo); reflection_object_handlers.free_obj = reflection_free_objects_storage; reflection_object_handlers.clone_obj = NULL; @@ -6838,10 +6733,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ PHP_MINFO_FUNCTION(reflection) /* {{{ */ { php_info_print_table_start(); - php_info_print_table_header(2, "Reflection", "enabled"); - - php_info_print_table_row(2, "Version", "$Id$"); - + php_info_print_table_row(2, "Reflection", "enabled"); php_info_print_table_end(); } /* }}} */ |