diff options
Diffstat (limited to 'ext/reflection')
88 files changed, 2885 insertions, 1643 deletions
diff --git a/ext/reflection/config.m4 b/ext/reflection/config.m4 index 702663677b..08f8e1ef5d 100755 --- a/ext/reflection/config.m4 +++ b/ext/reflection/config.m4 @@ -2,4 +2,4 @@ dnl $Id$ dnl config.m4 for extension reflection AC_DEFINE(HAVE_REFLECTION, 1, [Whether Reflection is enabled]) -PHP_NEW_EXTENSION(reflection, php_reflection.c, no) +PHP_NEW_EXTENSION(reflection, php_reflection.c, no,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) diff --git a/ext/reflection/config.w32 b/ext/reflection/config.w32 index 724bf7bde4..2eb33c66ee 100755 --- a/ext/reflection/config.w32 +++ b/ext/reflection/config.w32 @@ -1,6 +1,6 @@ // $Id$ // vim:ft=javascript -EXTENSION("reflection", "php_reflection.c", false /* never shared */); +EXTENSION("reflection", "php_reflection.c", false /* never shared */, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); AC_DEFINE('HAVE_REFLECTION', 1, 'Reflection support enabled'); -PHP_REFLECTION="yes";
\ No newline at end of file +PHP_REFLECTION="yes"; diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 5f15287237..1c13aa5090 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -39,14 +39,15 @@ #include "zend_ini.h" #include "zend_interfaces.h" #include "zend_closures.h" +#include "zend_generators.h" #include "zend_extensions.h" +#include "zend_builtin_functions.h" #define reflection_update_property(object, name, value) do { \ - zval *member; \ - MAKE_STD_ZVAL(member); \ - ZVAL_STRINGL(member, name, sizeof(name)-1, 1); \ - zend_std_write_property(object, member, value, NULL TSRMLS_CC); \ - Z_DELREF_P(value); \ + zval member; \ + ZVAL_STRINGL(&member, name, sizeof(name)-1); \ + zend_std_write_property(object, &member, value, NULL); \ + if (Z_REFCOUNTED_P(value)) Z_DELREF_P(value); \ zval_ptr_dtor(&member); \ } while (0) @@ -56,7 +57,9 @@ PHPAPI zend_class_entry *reflection_exception_ptr; PHPAPI zend_class_entry *reflection_ptr; PHPAPI zend_class_entry *reflection_function_abstract_ptr; PHPAPI zend_class_entry *reflection_function_ptr; +PHPAPI zend_class_entry *reflection_generator_ptr; PHPAPI zend_class_entry *reflection_parameter_ptr; +PHPAPI zend_class_entry *reflection_type_ptr; PHPAPI zend_class_entry *reflection_class_ptr; PHPAPI zend_class_entry *reflection_object_ptr; PHPAPI zend_class_entry *reflection_method_ptr; @@ -71,7 +74,7 @@ ZEND_END_MODULE_GLOBALS(reflection) #ifdef ZTS # define REFLECTION_G(v) \ - TSRMG(reflection_globals_id, zend_reflection_globals*, v) + ZEND_TSRMG(reflection_globals_id, zend_reflection_globals*, v) extern int reflection_globals_id; #else # define REFLECTION_G(v) (reflection_globals.v) @@ -84,97 +87,102 @@ ZEND_DECLARE_MODULE_GLOBALS(reflection) /* Method macros */ #define METHOD_NOTSTATIC(ce) \ - if (!this_ptr || !instanceof_function(Z_OBJCE_P(this_ptr), ce TSRMLS_CC)) { \ - php_error_docref(NULL TSRMLS_CC, E_ERROR, "%s() cannot be called statically", get_active_function_name(TSRMLS_C)); \ + if (!Z_OBJ(EX(This)) || !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 TSRMLS_CC); \ + zend_throw_exception(reflection_exception_ptr, msg, 0); \ return; \ #define RETURN_ON_EXCEPTION \ - if (EG(exception) && Z_OBJCE_P(EG(exception)) == reflection_exception_ptr) { \ + if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { \ return; \ } -#define GET_REFLECTION_OBJECT_PTR(target) \ - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); \ - if (intern == NULL || intern->ptr == NULL) { \ +#define GET_REFLECTION_OBJECT() \ + intern = Z_REFLECTION_P(getThis()); \ + if (intern->ptr == NULL) { \ RETURN_ON_EXCEPTION \ - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); \ + php_error_docref(NULL, E_ERROR, "Internal error: Failed to retrieve the reflection object"); \ } \ + +#define GET_REFLECTION_OBJECT_PTR(target) \ + GET_REFLECTION_OBJECT() \ target = intern->ptr; \ /* Class constants */ #define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \ - zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); + zend_declare_class_constant_long(reflection_ ## class_name ## _ptr, const_name, sizeof(const_name)-1, (zend_long)value); /* {{{ Smart string functions */ typedef struct _string { - char *string; - int len; - int alloced; + zend_string *buf; + size_t alloced; } string; static void string_init(string *str) { - str->string = (char *) emalloc(1024); - str->len = 1; + str->buf= zend_string_alloc(1024, 0); str->alloced = 1024; - *str->string = '\0'; + ZSTR_VAL(str->buf)[0] = '\0'; + ZSTR_LEN(str->buf) = 0; } static string *string_printf(string *str, const char *format, ...) { - int len; + size_t len; va_list arg; char *s_tmp; va_start(arg, format); len = zend_vspprintf(&s_tmp, 0, format, arg); if (len) { - register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1); + register size_t nlen = (ZSTR_LEN(str->buf) + 1 + len + (1024 - 1)) & ~(1024 - 1); if (str->alloced < nlen) { + size_t old_len = ZSTR_LEN(str->buf); str->alloced = nlen; - str->string = erealloc(str->string, str->alloced); + str->buf = zend_string_extend(str->buf, str->alloced, 0); + ZSTR_LEN(str->buf) = old_len; } - memcpy(str->string + str->len - 1, s_tmp, len + 1); - str->len += len; + memcpy(ZSTR_VAL(str->buf) + ZSTR_LEN(str->buf), s_tmp, len + 1); + ZSTR_LEN(str->buf) += len; } efree(s_tmp); va_end(arg); return str; } -static string *string_write(string *str, char *buf, int len) +static string *string_write(string *str, char *buf, size_t len) { - register int nlen = (str->len + len + (1024 - 1)) & ~(1024 - 1); + register size_t nlen = (ZSTR_LEN(str->buf) + 1 + len + (1024 - 1)) & ~(1024 - 1); if (str->alloced < nlen) { + size_t old_len = ZSTR_LEN(str->buf); str->alloced = nlen; - str->string = erealloc(str->string, str->alloced); + str->buf = zend_string_extend(str->buf, str->alloced, 0); + ZSTR_LEN(str->buf) = old_len; } - memcpy(str->string + str->len - 1, buf, len); - str->len += len; - str->string[str->len - 1] = '\0'; + memcpy(ZSTR_VAL(str->buf) + ZSTR_LEN(str->buf), buf, len); + ZSTR_LEN(str->buf) += len; + ZSTR_VAL(str->buf)[ZSTR_LEN(str->buf)] = '\0'; return str; } static string *string_append(string *str, string *append) { - if (append->len > 1) { - string_write(str, append->string, append->len - 1); + if (ZSTR_LEN(append->buf) > 0) { + string_write(str, ZSTR_VAL(append->buf), ZSTR_LEN(append->buf)); } return str; } static void string_free(string *str) { - efree(str->string); - str->len = 0; + zend_string_release(str->buf); str->alloced = 0; - str->string = NULL; + str->buf = NULL; } /* }}} */ @@ -188,48 +196,72 @@ typedef struct _property_reference { /* Struct for parameters */ typedef struct _parameter_reference { - zend_uint offset; - zend_uint required; + uint32_t offset; + uint32_t required; struct _zend_arg_info *arg_info; zend_function *fptr; } parameter_reference; +/* Struct for type hints */ +typedef struct _type_reference { + struct _zend_arg_info *arg_info; + zend_function *fptr; +} type_reference; + typedef enum { REF_TYPE_OTHER, /* Must be 0 */ REF_TYPE_FUNCTION, + REF_TYPE_GENERATOR, REF_TYPE_PARAMETER, + REF_TYPE_TYPE, REF_TYPE_PROPERTY, REF_TYPE_DYNAMIC_PROPERTY } reflection_type_t; /* Struct for reflection objects */ typedef struct { - zend_object zo; + zval dummy; /* holder for the second property */ + zval obj; void *ptr; - reflection_type_t ref_type; - zval *obj; zend_class_entry *ce; + reflection_type_t ref_type; unsigned int ignore_visibility:1; + zend_object zo; } reflection_object; +static inline reflection_object *reflection_object_from_obj(zend_object *obj) { + return (reflection_object*)((char*)(obj) - XtOffsetOf(reflection_object, zo)); +} + +#define Z_REFLECTION_P(zv) reflection_object_from_obj(Z_OBJ_P((zv))) /* }}} */ static zend_object_handlers reflection_object_handlers; -static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value TSRMLS_DC) /* {{{ */ +static zval *_default_load_entry(zval *object, char *name, size_t name_len) /* {{{ */ { - zval **value; + zval *value; - if (zend_hash_find(Z_OBJPROP_P(object), name, name_len, (void **) &value) == FAILURE) { - RETURN_FALSE; + if ((value = zend_hash_str_find_ind(Z_OBJPROP_P(object), name, name_len)) == NULL) { + return NULL; } + return value; +} +/* }}} */ - MAKE_COPY_ZVAL(value, return_value); +static void _default_get_entry(zval *object, char *name, int name_len, zval *return_value) /* {{{ */ +{ + zval *value; + + if ((value = _default_load_entry(object, name, name_len)) == NULL) { + RETURN_FALSE; + } + ZVAL_DUP(return_value, value); } /* }}} */ #ifdef ilia_0 -static void _default_lookup_entry(zval *object, char *name, int name_len, zval **return_value TSRMLS_DC) /* {{{ */ +static void _default_lookup_entry(zval *object, char *name, int name_len, zval **return_value) /* {{{ */ { zval **value; @@ -242,44 +274,15 @@ static void _default_lookup_entry(zval *object, char *name, int name_len, zval * /* }}} */ #endif -static void reflection_zval_deep_copy(zval **p) -{ - zval *value; - - ALLOC_ZVAL(value); - *value = **p; - if (Z_TYPE_P(value) == IS_ARRAY) { - HashTable *ht; - - ALLOC_HASHTABLE(ht); - zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(value)), NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(ht, Z_ARRVAL_P(value), (copy_ctor_func_t) reflection_zval_deep_copy, NULL, sizeof(zval *)); - Z_ARRVAL_P(value) = ht; - } else { - zval_copy_ctor(value); - } - INIT_PZVAL(value); - *p = value; -} -static void reflection_register_implement(zend_class_entry *class_entry, zend_class_entry *interface_entry TSRMLS_DC) /* {{{ */ -{ - zend_uint num_interfaces = ++class_entry->num_interfaces; - - class_entry->interfaces = (zend_class_entry **) realloc(class_entry->interfaces, sizeof(zend_class_entry *) * num_interfaces); - class_entry->interfaces[num_interfaces - 1] = interface_entry; -} -/* }}} */ - -static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */ +static zend_function *_copy_function(zend_function *fptr) /* {{{ */ { if (fptr - && fptr->type == ZEND_INTERNAL_FUNCTION - && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) + && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { zend_function *copy_fptr; copy_fptr = emalloc(sizeof(zend_function)); memcpy(copy_fptr, fptr, sizeof(zend_function)); - copy_fptr->internal_function.function_name = estrdup(fptr->internal_function.function_name); + copy_fptr->internal_function.function_name = zend_string_copy(fptr->internal_function.function_name); return copy_fptr; } else { /* no copy needed */ @@ -288,92 +291,98 @@ static zend_function *_copy_function(zend_function *fptr TSRMLS_DC) /* {{{ */ } /* }}} */ -static void _free_function(zend_function *fptr TSRMLS_DC) /* {{{ */ +static void _free_function(zend_function *fptr) /* {{{ */ { if (fptr - && fptr->type == ZEND_INTERNAL_FUNCTION - && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) + && (fptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { - efree((char*)fptr->internal_function.function_name); - efree(fptr); + zend_string_release(fptr->internal_function.function_name); + zend_free_trampoline(fptr); } } /* }}} */ -static void reflection_free_objects_storage(void *object TSRMLS_DC) /* {{{ */ +static void reflection_free_objects_storage(zend_object *object) /* {{{ */ { - reflection_object *intern = (reflection_object *) object; + reflection_object *intern = reflection_object_from_obj(object); parameter_reference *reference; property_reference *prop_reference; + type_reference *typ_reference; if (intern->ptr) { switch (intern->ref_type) { case REF_TYPE_PARAMETER: reference = (parameter_reference*)intern->ptr; - _free_function(reference->fptr TSRMLS_CC); + _free_function(reference->fptr); + efree(intern->ptr); + break; + case REF_TYPE_TYPE: + typ_reference = (type_reference*)intern->ptr; + _free_function(typ_reference->fptr); efree(intern->ptr); break; case REF_TYPE_FUNCTION: - _free_function(intern->ptr TSRMLS_CC); + _free_function(intern->ptr); break; case REF_TYPE_PROPERTY: efree(intern->ptr); break; case REF_TYPE_DYNAMIC_PROPERTY: prop_reference = (property_reference*)intern->ptr; - efree((char*)prop_reference->prop.name); + zend_string_release(prop_reference->prop.name); efree(intern->ptr); break; + case REF_TYPE_GENERATOR: + break; case REF_TYPE_OTHER: break; } } intern->ptr = NULL; - if (intern->obj) { - zval_ptr_dtor(&intern->obj); - } - zend_objects_free_object_storage(object TSRMLS_CC); + zval_ptr_dtor(&intern->obj); + zend_object_std_dtor(object); +} +/* }}} */ + +static HashTable *reflection_get_gc(zval *obj, zval **gc_data, int *gc_data_count) /* {{{ */ +{ + reflection_object *intern = Z_REFLECTION_P(obj); + *gc_data = &intern->obj; + *gc_data_count = 1; + return zend_std_get_properties(obj); } /* }}} */ -static zend_object_value reflection_objects_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */ +static zend_object *reflection_objects_new(zend_class_entry *class_type) /* {{{ */ { - zend_object_value retval; reflection_object *intern; - intern = ecalloc(1, sizeof(reflection_object)); + intern = ecalloc(1, sizeof(reflection_object) + zend_object_properties_size(class_type)); intern->zo.ce = class_type; - zend_object_std_init(&intern->zo, class_type TSRMLS_CC); + zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); - retval.handle = zend_objects_store_put(intern, NULL, reflection_free_objects_storage, NULL TSRMLS_CC); - retval.handlers = &reflection_object_handlers; - return retval; + intern->zo.handlers = &reflection_object_handlers; + return &intern->zo; } /* }}} */ -static zval * reflection_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC) /* {{{ */ +static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{ */ { - if (!object) { - ALLOC_ZVAL(object); - } - Z_TYPE_P(object) = IS_OBJECT; object_init_ex(object, pce); - Z_SET_REFCOUNT_P(object, 1); - Z_SET_ISREF_P(object); return object; } /* }}} */ -static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC); -static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent TSRMLS_DC); -static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent TSRMLS_DC); -static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC); -static void _extension_string(string *str, zend_module_entry *module, char *indent TSRMLS_DC); -static void _zend_extension_string(string *str, zend_extension *extension, char *indent TSRMLS_DC); +static void _const_string(string *str, char *name, zval *value, char *indent); +static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent); +static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent); +static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent); +static void _extension_string(string *str, zend_module_entry *module, char *indent); +static void _zend_extension_string(string *str, zend_extension *extension, char *indent); /* {{{ _class_string */ -static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent TSRMLS_DC) +static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *indent) { int count, count_static_props = 0, count_static_funcs = 0, count_shadow_props = 0; string sub_indent; @@ -383,17 +392,17 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in /* TBD: Repair indenting of doc comment (or is this to be done in the parser?) */ if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) { - string_printf(str, "%s%s", indent, ce->info.user.doc_comment); + string_printf(str, "%s%s", indent, ZSTR_VAL(ce->info.user.doc_comment)); string_write(str, "\n", 1); } - if (obj) { + if (obj && Z_TYPE_P(obj) == IS_OBJECT) { string_printf(str, "%sObject of class [ ", indent); } else { char *kind = "Class"; if (ce->ce_flags & ZEND_ACC_INTERFACE) { kind = "Interface"; - } else if ((ce->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { + } else if (ce->ce_flags & ZEND_ACC_TRAIT) { kind = "Trait"; } string_printf(str, "%s%s [ ", indent, kind); @@ -408,197 +417,149 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } if (ce->ce_flags & ZEND_ACC_INTERFACE) { string_printf(str, "interface "); - } else if ((ce->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) { + } else if (ce->ce_flags & ZEND_ACC_TRAIT) { string_printf(str, "trait "); } else { if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { string_printf(str, "abstract "); } - if (ce->ce_flags & ZEND_ACC_FINAL_CLASS) { + if (ce->ce_flags & ZEND_ACC_FINAL) { string_printf(str, "final "); } string_printf(str, "class "); } - string_printf(str, "%s", ce->name); + string_printf(str, "%s", ZSTR_VAL(ce->name)); if (ce->parent) { - string_printf(str, " extends %s", ce->parent->name); + string_printf(str, " extends %s", ZSTR_VAL(ce->parent->name)); } if (ce->num_interfaces) { - zend_uint i; + uint32_t i; if (ce->ce_flags & ZEND_ACC_INTERFACE) { - string_printf(str, " extends %s", ce->interfaces[0]->name); + string_printf(str, " extends %s", ZSTR_VAL(ce->interfaces[0]->name)); } else { - string_printf(str, " implements %s", ce->interfaces[0]->name); + string_printf(str, " implements %s", ZSTR_VAL(ce->interfaces[0]->name)); } for (i = 1; i < ce->num_interfaces; ++i) { - string_printf(str, ", %s", ce->interfaces[i]->name); + string_printf(str, ", %s", ZSTR_VAL(ce->interfaces[i]->name)); } } string_printf(str, " ] {\n"); /* The information where a class is declared is only available for user classes */ if (ce->type == ZEND_USER_CLASS) { - string_printf(str, "%s @@ %s %d-%d\n", indent, ce->info.user.filename, + string_printf(str, "%s @@ %s %d-%d\n", indent, ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start, ce->info.user.line_end); } /* Constants */ - if (&ce->constants_table) { - zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t) zval_update_constant, (void*)1 TSRMLS_CC); - string_printf(str, "\n"); - count = zend_hash_num_elements(&ce->constants_table); - string_printf(str, "%s - Constants [%d] {\n", indent, count); - if (count > 0) { - HashPosition pos; - zval **value; - char *key; - uint key_len; - ulong num_index; - - zend_hash_internal_pointer_reset_ex(&ce->constants_table, &pos); - - while (zend_hash_get_current_data_ex(&ce->constants_table, (void **) &value, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&ce->constants_table, &key, &key_len, &num_index, 0, &pos); - - _const_string(str, key, *value, indent TSRMLS_CC); - zend_hash_move_forward_ex(&ce->constants_table, &pos); - } - } - string_printf(str, "%s }\n", indent); + string_printf(str, "\n"); + count = zend_hash_num_elements(&ce->constants_table); + string_printf(str, "%s - Constants [%d] {\n", indent, count); + if (count > 0) { + zend_string *key; + zval *value; + + ZEND_HASH_FOREACH_STR_KEY_VAL(&ce->constants_table, key, value) { + zval_update_constant_ex(value, 1, NULL); + _const_string(str, ZSTR_VAL(key), value, indent); + } ZEND_HASH_FOREACH_END(); } + string_printf(str, "%s }\n", indent); /* Static properties */ - if (&ce->properties_info) { - /* counting static properties */ - count = zend_hash_num_elements(&ce->properties_info); - if (count > 0) { - HashPosition pos; - zend_property_info *prop; - - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if(prop->flags & ZEND_ACC_SHADOW) { - count_shadow_props++; - } else if (prop->flags & ZEND_ACC_STATIC) { - count_static_props++; - } - zend_hash_move_forward_ex(&ce->properties_info, &pos); + /* counting static properties */ + count = zend_hash_num_elements(&ce->properties_info); + if (count > 0) { + zend_property_info *prop; + + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + if(prop->flags & ZEND_ACC_SHADOW) { + count_shadow_props++; + } else if (prop->flags & ZEND_ACC_STATIC) { + count_static_props++; } - } - - /* static properties */ - string_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props); - if (count_static_props > 0) { - HashPosition pos; - zend_property_info *prop; + } ZEND_HASH_FOREACH_END(); + } - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); + /* static properties */ + string_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props); + if (count_static_props > 0) { + zend_property_info *prop; - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { - _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); - } - - zend_hash_move_forward_ex(&ce->properties_info, &pos); + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + if ((prop->flags & ZEND_ACC_STATIC) && !(prop->flags & ZEND_ACC_SHADOW)) { + _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.buf)); } - } - string_printf(str, "%s }\n", indent); + } ZEND_HASH_FOREACH_END(); } + string_printf(str, "%s }\n", indent); /* Static methods */ - if (&ce->function_table) { - /* counting static methods */ - count = zend_hash_num_elements(&ce->function_table); - if (count > 0) { - HashPosition pos; - zend_function *mptr; - - zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { - if (mptr->common.fn_flags & ZEND_ACC_STATIC - && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) - { - count_static_funcs++; - } - zend_hash_move_forward_ex(&ce->function_table, &pos); + /* counting static methods */ + count = zend_hash_num_elements(&ce->function_table); + if (count > 0) { + zend_function *mptr; + + ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + if (mptr->common.fn_flags & ZEND_ACC_STATIC + && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) + { + count_static_funcs++; } - } - - /* static methods */ - string_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs); - if (count_static_funcs > 0) { - HashPosition pos; - zend_function *mptr; + } ZEND_HASH_FOREACH_END(); + } - zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); + /* static methods */ + string_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs); + if (count_static_funcs > 0) { + zend_function *mptr; - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { - if (mptr->common.fn_flags & ZEND_ACC_STATIC - && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) - { - string_printf(str, "\n"); - _function_string(str, mptr, ce, sub_indent.string TSRMLS_CC); - } - zend_hash_move_forward_ex(&ce->function_table, &pos); + ZEND_HASH_FOREACH_PTR(&ce->function_table, mptr) { + if (mptr->common.fn_flags & ZEND_ACC_STATIC + && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) + { + string_printf(str, "\n"); + _function_string(str, mptr, ce, ZSTR_VAL(sub_indent.buf)); } - } else { - string_printf(str, "\n"); - } - string_printf(str, "%s }\n", indent); + } ZEND_HASH_FOREACH_END(); + } else { + string_printf(str, "\n"); } + string_printf(str, "%s }\n", indent); /* Default/Implicit properties */ - if (&ce->properties_info) { - count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; - string_printf(str, "\n%s - Properties [%d] {\n", indent, count); - if (count > 0) { - HashPosition pos; - zend_property_info *prop; - - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop, &pos) == SUCCESS) { - if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { - _property_string(str, prop, NULL, sub_indent.string TSRMLS_CC); - } - zend_hash_move_forward_ex(&ce->properties_info, &pos); + count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props; + string_printf(str, "\n%s - Properties [%d] {\n", indent, count); + if (count > 0) { + zend_property_info *prop; + + ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { + if (!(prop->flags & (ZEND_ACC_STATIC|ZEND_ACC_SHADOW))) { + _property_string(str, prop, NULL, ZSTR_VAL(sub_indent.buf)); } - } - string_printf(str, "%s }\n", indent); + } ZEND_HASH_FOREACH_END(); } + string_printf(str, "%s }\n", indent); - if (obj && Z_OBJ_HT_P(obj)->get_properties) { + if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) { string dyn; - HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj TSRMLS_CC); - HashPosition pos; - zval **prop; + HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj); + zend_string *prop_name; string_init(&dyn); count = 0; if (properties && zend_hash_num_elements(properties)) { - zend_hash_internal_pointer_reset_ex(properties, &pos); - - while (zend_hash_get_current_data_ex(properties, (void **) &prop, &pos) == SUCCESS) { - char *prop_name; - uint prop_name_size; - ulong index; - - if (zend_hash_get_current_key_ex(properties, &prop_name, &prop_name_size, &index, 1, &pos) == HASH_KEY_IS_STRING) { - if (prop_name_size && prop_name[0]) { /* skip all private and protected properties */ - if (!zend_hash_quick_exists(&ce->properties_info, prop_name, prop_name_size, zend_get_hash_value(prop_name, prop_name_size))) { - count++; - _property_string(&dyn, NULL, prop_name, sub_indent.string TSRMLS_CC); - } + ZEND_HASH_FOREACH_STR_KEY(properties, 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++; + _property_string(&dyn, NULL, ZSTR_VAL(prop_name), ZSTR_VAL(sub_indent.buf)); } - efree(prop_name); } - zend_hash_move_forward_ex(properties, &pos); - } + } ZEND_HASH_FOREACH_END(); } string_printf(str, "\n%s - Dynamic properties [%d] {\n", indent, count); @@ -608,61 +569,54 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in } /* Non static methods */ - if (&ce->function_table) { - count = zend_hash_num_elements(&ce->function_table) - count_static_funcs; - if (count > 0) { - HashPosition pos; - zend_function *mptr; - string dyn; - - count = 0; - string_init(&dyn); - zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); - - while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { - if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 - && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) + count = zend_hash_num_elements(&ce->function_table) - count_static_funcs; + if (count > 0) { + zend_function *mptr; + zend_string *key; + string dyn; + + count = 0; + string_init(&dyn); + + ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, mptr) { + if ((mptr->common.fn_flags & ZEND_ACC_STATIC) == 0 + && ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce)) + { + size_t len = ZSTR_LEN(mptr->common.function_name); + + /* Do not display old-style inherited constructors */ + if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 + || mptr->common.scope == ce + || !key + || zend_binary_strcasecmp(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(mptr->common.function_name), len) == 0) { - char *key; - uint key_len; - ulong num_index; - uint len = strlen(mptr->common.function_name); - - /* Do not display old-style inherited constructors */ - if ((mptr->common.fn_flags & ZEND_ACC_CTOR) == 0 - || mptr->common.scope == ce - || zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &num_index, 0, &pos) != HASH_KEY_IS_STRING - || zend_binary_strcasecmp(key, key_len-1, mptr->common.function_name, len) == 0) + zend_function *closure; + /* see if this is a closure */ + if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + && 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) { - zend_function *closure; - /* see if this is a closure */ - if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) - && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL) - { - mptr = closure; - } else { - closure = NULL; - } - string_printf(&dyn, "\n"); - _function_string(&dyn, mptr, ce, sub_indent.string TSRMLS_CC); - count++; - _free_function(closure TSRMLS_CC); + mptr = closure; + } else { + closure = NULL; } + string_printf(&dyn, "\n"); + _function_string(&dyn, mptr, ce, ZSTR_VAL(sub_indent.buf)); + count++; + _free_function(closure); } - zend_hash_move_forward_ex(&ce->function_table, &pos); - } - string_printf(str, "\n%s - Methods [%d] {", indent, count); - if (!count) { - string_printf(str, "\n"); } - string_append(str, &dyn); - string_free(&dyn); - } else { - string_printf(str, "\n%s - Methods [0] {\n", indent); + } ZEND_HASH_FOREACH_END(); + string_printf(str, "\n%s - Methods [%d] {", indent, count); + if (!count) { + string_printf(str, "\n"); } - string_printf(str, "%s }\n", indent); + string_append(str, &dyn); + string_free(&dyn); + } else { + string_printf(str, "\n%s - Methods [0] {\n", indent); } + string_printf(str, "%s }\n", indent); string_printf(str, "%s}\n", indent); string_free(&sub_indent); @@ -670,43 +624,32 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in /* }}} */ /* {{{ _const_string */ -static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC) +static void _const_string(string *str, char *name, zval *value, char *indent) { - char *type; - type = zend_zval_type_name(value); + char *type = zend_zval_type_name(value); if (Z_TYPE_P(value) == IS_ARRAY) { string_printf(str, "%s Constant [ %s %s ] { Array }\n", indent, type, name); } else { - zval value_copy; - int use_copy; - - zend_make_printable_zval(value, &value_copy, &use_copy); - if (use_copy) { - value = &value_copy; - } - + zend_string *value_str = zval_get_string(value); string_printf(str, "%s Constant [ %s %s ] { %s }\n", - indent, type, name, Z_STRVAL_P(value)); - - if (use_copy) { - zval_dtor(value); - } + indent, type, name, ZSTR_VAL(value_str)); + zend_string_release(value_str); } } /* }}} */ /* {{{ _get_recv_opcode */ -static zend_op* _get_recv_op(zend_op_array *op_array, zend_uint offset) +static zend_op* _get_recv_op(zend_op_array *op_array, uint32_t offset) { zend_op *op = op_array->opcodes; zend_op *end = op + op_array->last; ++offset; while (op < end) { - if ((op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT - || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == (long)offset) + if ((op->opcode == ZEND_RECV || op->opcode == ZEND_RECV_INIT + || op->opcode == ZEND_RECV_VARIADIC) && op->op1.num == (zend_long)offset) { return op; } @@ -717,7 +660,7 @@ static zend_op* _get_recv_op(zend_op_array *op_array, zend_uint offset) /* }}} */ /* {{{ _parameter_string */ -static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, zend_uint offset, zend_uint required, char* indent TSRMLS_DC) +static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg_info *arg_info, uint32_t offset, uint32_t required, char* indent) { string_printf(str, "Parameter #%d [ ", offset); if (offset >= required) { @@ -726,7 +669,11 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg string_printf(str, "<required> "); } if (arg_info->class_name) { - string_printf(str, "%s ", arg_info->class_name); + string_printf(str, "%s ", + (fptr->type == ZEND_INTERNAL_FUNCTION && + !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? + ((zend_internal_arg_info*)arg_info)->class_name : + ZSTR_VAL(arg_info->class_name)); if (arg_info->allow_null) { string_printf(str, "or NULL "); } @@ -743,57 +690,47 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg string_write(str, "...", sizeof("...")-1); } if (arg_info->name) { - string_printf(str, "$%s", arg_info->name); + string_printf(str, "$%s", + (fptr->type == ZEND_INTERNAL_FUNCTION && + !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? + ((zend_internal_arg_info*)arg_info)->name : + ZSTR_VAL(arg_info->name)); } else { string_printf(str, "$param%d", offset); } if (fptr->type == ZEND_USER_FUNCTION && offset >= required) { zend_op *precv = _get_recv_op((zend_op_array*)fptr, offset); if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) { - zval *zv, zv_copy; - int use_copy; + zval zv; zend_class_entry *old_scope; string_write(str, " = ", sizeof(" = ")-1); - if (IS_CONSTANT_TYPE(Z_TYPE_P(precv->op2.zv))) { - ALLOC_ZVAL(zv); - *zv = *precv->op2.zv; - zval_copy_ctor(zv); - INIT_PZVAL(zv); - old_scope = EG(scope); - EG(scope) = fptr->common.scope; - zval_update_constant_ex(&zv, 1, NULL TSRMLS_CC); - EG(scope) = old_scope; - } else { - zv = precv->op2.zv; - } - if (Z_TYPE_P(zv) == IS_BOOL) { - if (Z_LVAL_P(zv)) { - string_write(str, "true", sizeof("true")-1); - } else { - string_write(str, "false", sizeof("false")-1); - } - } else if (Z_TYPE_P(zv) == IS_NULL) { + ZVAL_DUP(&zv, RT_CONSTANT(&fptr->op_array, precv->op2)); + old_scope = EG(scope); + EG(scope) = fptr->common.scope; + zval_update_constant_ex(&zv, 1, NULL); + EG(scope) = old_scope; + if (Z_TYPE(zv) == IS_TRUE) { + string_write(str, "true", sizeof("true")-1); + } else if (Z_TYPE(zv) == IS_FALSE) { + string_write(str, "false", sizeof("false")-1); + } else if (Z_TYPE(zv) == IS_NULL) { string_write(str, "NULL", sizeof("NULL")-1); - } else if (Z_TYPE_P(zv) == IS_STRING) { + } else if (Z_TYPE(zv) == IS_STRING) { string_write(str, "'", sizeof("'")-1); - string_write(str, Z_STRVAL_P(zv), MIN(Z_STRLEN_P(zv), 15)); - if (Z_STRLEN_P(zv) > 15) { + string_write(str, Z_STRVAL(zv), MIN(Z_STRLEN(zv), 15)); + if (Z_STRLEN(zv) > 15) { string_write(str, "...", sizeof("...")-1); } string_write(str, "'", sizeof("'")-1); - } else if (Z_TYPE_P(zv) == IS_ARRAY) { + } else if (Z_TYPE(zv) == IS_ARRAY) { string_write(str, "Array", sizeof("Array")-1); } else { - zend_make_printable_zval(zv, &zv_copy, &use_copy); - string_write(str, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy)); - if (use_copy) { - zval_dtor(&zv_copy); - } - } - if (zv != precv->op2.zv) { - zval_ptr_dtor(&zv); + zend_string *zv_str = zval_get_string(&zv); + string_write(str, ZSTR_VAL(zv_str), ZSTR_LEN(zv_str)); + zend_string_release(zv_str); } + zval_ptr_dtor(&zv); } } string_write(str, " ]", sizeof(" ]")-1); @@ -801,20 +738,24 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg /* }}} */ /* {{{ _function_parameter_string */ -static void _function_parameter_string(string *str, zend_function *fptr, char* indent TSRMLS_DC) +static void _function_parameter_string(string *str, zend_function *fptr, char* indent) { struct _zend_arg_info *arg_info = fptr->common.arg_info; - zend_uint i, required = fptr->common.required_num_args; + uint32_t i, num_args, required = fptr->common.required_num_args; if (!arg_info) { return; } + num_args = fptr->common.num_args; + if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { + num_args++; + } string_printf(str, "\n"); - string_printf(str, "%s- Parameters [%d] {\n", indent, fptr->common.num_args); - for (i = 0; i < fptr->common.num_args; i++) { + string_printf(str, "%s- Parameters [%d] {\n", indent, num_args); + for (i = 0; i < num_args; i++) { string_printf(str, "%s ", indent); - _parameter_string(str, fptr, arg_info, i, required, indent TSRMLS_CC); + _parameter_string(str, fptr, arg_info, i, required, indent); string_write(str, "\n", sizeof("\n")-1); arg_info++; } @@ -823,14 +764,11 @@ static void _function_parameter_string(string *str, zend_function *fptr, char* i /* }}} */ /* {{{ _function_closure_string */ -static void _function_closure_string(string *str, zend_function *fptr, char* indent TSRMLS_DC) +static void _function_closure_string(string *str, zend_function *fptr, char* indent) { - zend_uint i, count; - ulong num_index; - char *key; - uint key_len; + uint32_t i, count; + zend_string *key; HashTable *static_variables; - HashPosition pos; if (fptr->type != ZEND_USER_FUNCTION || !fptr->op_array.static_variables) { return; @@ -845,31 +783,28 @@ static void _function_closure_string(string *str, zend_function *fptr, char* ind string_printf(str, "\n"); string_printf(str, "%s- Bound Variables [%d] {\n", indent, zend_hash_num_elements(static_variables)); - zend_hash_internal_pointer_reset_ex(static_variables, &pos); i = 0; - while (i < count) { - zend_hash_get_current_key_ex(static_variables, &key, &key_len, &num_index, 0, &pos); - string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, key); - zend_hash_move_forward_ex(static_variables, &pos); - } + ZEND_HASH_FOREACH_STR_KEY(static_variables, key) { + string_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key)); + } ZEND_HASH_FOREACH_END(); string_printf(str, "%s}\n", indent); } /* }}} */ /* {{{ _function_string */ -static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent TSRMLS_DC) +static void _function_string(string *str, zend_function *fptr, zend_class_entry *scope, char* indent) { string param_indent; zend_function *overwrites; - char *lc_name; - unsigned int lc_name_len; + 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 * swallowed, leading to an unaligned comment. */ if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - string_printf(str, "%s%s\n", indent, fptr->op_array.doc_comment); + string_printf(str, "%s%s\n", indent, ZSTR_VAL(fptr->op_array.doc_comment)); } string_write(str, indent, strlen(indent)); @@ -884,20 +819,21 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry if (scope && fptr->common.scope) { if (fptr->common.scope != scope) { - string_printf(str, ", inherits %s", fptr->common.scope->name); + string_printf(str, ", inherits %s", ZSTR_VAL(fptr->common.scope->name)); } else if (fptr->common.scope->parent) { - lc_name_len = strlen(fptr->common.function_name); - lc_name = zend_str_tolower_dup(fptr->common.function_name, lc_name_len); - if (zend_hash_find(&fptr->common.scope->parent->function_table, lc_name, lc_name_len + 1, (void**) &overwrites) == SUCCESS) { + 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); + if ((overwrites = zend_hash_find_ptr(&fptr->common.scope->parent->function_table, lc_name)) != NULL) { if (fptr->common.scope != overwrites->common.scope) { - string_printf(str, ", overwrites %s", overwrites->common.scope->name); + string_printf(str, ", overwrites %s", ZSTR_VAL(overwrites->common.scope->name)); } } efree(lc_name); } } if (fptr->common.prototype && fptr->common.prototype->common.scope) { - string_printf(str, ", prototype %s", fptr->common.prototype->common.scope->name); + string_printf(str, ", prototype %s", ZSTR_VAL(fptr->common.prototype->common.scope->name)); } if (fptr->common.fn_flags & ZEND_ACC_CTOR) { string_printf(str, ", ctor"); @@ -941,27 +877,46 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) { string_printf(str, "&"); } - string_printf(str, "%s ] {\n", fptr->common.function_name); + string_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name)); /* The information where a function is declared is only available for user classes */ if (fptr->type == ZEND_USER_FUNCTION) { string_printf(str, "%s @@ %s %d - %d\n", indent, - fptr->op_array.filename, + ZSTR_VAL(fptr->op_array.filename), fptr->op_array.line_start, fptr->op_array.line_end); } string_init(¶m_indent); string_printf(¶m_indent, "%s ", indent); if (fptr->common.fn_flags & ZEND_ACC_CLOSURE) { - _function_closure_string(str, fptr, param_indent.string TSRMLS_CC); + _function_closure_string(str, fptr, ZSTR_VAL(param_indent.buf)); } - _function_parameter_string(str, fptr, param_indent.string TSRMLS_CC); + _function_parameter_string(str, fptr, ZSTR_VAL(param_indent.buf)); string_free(¶m_indent); + if (fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { + string_printf(str, " %s- Return [ ", indent); + if (fptr->common.arg_info[-1].class_name) { + string_printf(str, "%s ", + (fptr->type == ZEND_INTERNAL_FUNCTION && + !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? + ((zend_internal_arg_info*)(fptr->common.arg_info - 1))->class_name : + ZSTR_VAL(fptr->common.arg_info[-1].class_name)); + if (fptr->common.arg_info[-1].allow_null) { + string_printf(str, "or NULL "); + } + } else if (fptr->common.arg_info[-1].type_hint) { + string_printf(str, "%s ", zend_get_type_by_const(fptr->common.arg_info[-1].type_hint)); + if (fptr->common.arg_info[-1].allow_null) { + string_printf(str, "or NULL "); + } + } + string_printf(str, "]\n"); + } string_printf(str, "%s}\n", indent); } /* }}} */ /* {{{ _property_string */ -static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent TSRMLS_DC) +static void _property_string(string *str, zend_property_info *prop, char *prop_name, char* indent) { const char *class_name; @@ -993,7 +948,7 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n string_printf(str, "static "); } - zend_unmangle_property_name(prop->name, prop->name_length, &class_name, (const char**)&prop_name); + zend_unmangle_property_name(prop->name, &class_name, (const char**)&prop_name); string_printf(str, "$%s", prop_name); } @@ -1001,15 +956,16 @@ static void _property_string(string *str, zend_property_info *prop, char *prop_n } /* }}} */ -static int _extension_ini_string(zend_ini_entry *ini_entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _extension_ini_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { + zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); string *str = va_arg(args, string *); char *indent = va_arg(args, char *); int number = va_arg(args, int); char *comma = ""; if (number == ini_entry->module_number) { - string_printf(str, " %sEntry [ %s <", indent, ini_entry->name); + string_printf(str, " %sEntry [ %s <", indent, ZSTR_VAL(ini_entry->name)); if (ini_entry->modifiable == ZEND_INI_ALL) { string_printf(str, "ALL"); } else { @@ -1027,9 +983,9 @@ static int _extension_ini_string(zend_ini_entry *ini_entry TSRMLS_DC, int num_ar } string_printf(str, "> ]\n"); - string_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ini_entry->value : ""); + string_printf(str, " %s Current = '%s'\n", indent, ini_entry->value ? ZSTR_VAL(ini_entry->value) : ""); if (ini_entry->modified) { - string_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ini_entry->orig_value : ""); + string_printf(str, " %s Default = '%s'\n", indent, ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : ""); } string_printf(str, " %s}\n", indent); } @@ -1037,18 +993,19 @@ static int _extension_ini_string(zend_ini_entry *ini_entry TSRMLS_DC, int num_ar } /* }}} */ -static int _extension_class_string(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _extension_class_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { + zend_class_entry *ce = (zend_class_entry*)Z_PTR_P(el); string *str = va_arg(args, string *); char *indent = va_arg(args, char *); struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int *num_classes = va_arg(args, int*); - if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->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_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) { + if (!zend_binary_strcasecmp(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key))) { string_printf(str, "\n"); - _class_string(str, *pce, NULL, indent TSRMLS_CC); + _class_string(str, ce, NULL, indent); (*num_classes)++; } } @@ -1056,23 +1013,23 @@ static int _extension_class_string(zend_class_entry **pce TSRMLS_DC, int num_arg } /* }}} */ -static int _extension_const_string(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _extension_const_string(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { + zend_constant *constant = (zend_constant*)Z_PTR_P(el); string *str = va_arg(args, string *); char *indent = va_arg(args, char *); 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) { - _const_string(str, constant->name, &constant->value, indent TSRMLS_CC); + _const_string(str, ZSTR_VAL(constant->name), &constant->value, indent); (*num_classes)++; } return ZEND_HASH_APPLY_KEEP; } /* }}} */ -/* {{{ _extension_string */ -static void _extension_string(string *str, zend_module_entry *module, char *indent TSRMLS_DC) +static void _extension_string(string *str, zend_module_entry *module, char *indent) /* {{{ */ { string_printf(str, "%sExtension [ ", indent); if (module->type == MODULE_PERSISTENT) { @@ -1123,8 +1080,8 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde { string str_ini; string_init(&str_ini); - zend_hash_apply_with_arguments(EG(ini_directives) TSRMLS_CC, (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number); - if (str_ini.len > 1) { + zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) _extension_ini_string, 3, &str_ini, indent, module->module_number); + if (ZSTR_LEN(str_ini.buf) > 0) { string_printf(str, "\n - INI {\n"); string_append(str, &str_ini); string_printf(str, "%s }\n", indent); @@ -1137,7 +1094,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde int num_constants = 0; string_init(&str_constants); - zend_hash_apply_with_arguments(EG(zend_constants) TSRMLS_CC, (apply_func_args_t) _extension_const_string, 4, &str_constants, indent, module, &num_constants); + zend_hash_apply_with_arguments(EG(zend_constants), (apply_func_args_t) _extension_const_string, 4, &str_constants, indent, module, &num_constants); if (num_constants) { string_printf(str, "\n - Constants [%d] {\n", num_constants); string_append(str, &str_constants); @@ -1147,22 +1104,19 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde } { - HashPosition iterator; zend_function *fptr; int first = 1; - zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); - while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { if (first) { string_printf(str, "\n - Functions {\n"); first = 0; } - _function_string(str, fptr, NULL, " " TSRMLS_CC); + _function_string(str, fptr, NULL, " "); } - zend_hash_move_forward_ex(CG(function_table), &iterator); - } + } ZEND_HASH_FOREACH_END(); if (!first) { string_printf(str, "%s }\n", indent); } @@ -1176,7 +1130,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde string_init(&sub_indent); string_printf(&sub_indent, "%s ", indent); string_init(&str_classes); - zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) _extension_class_string, 4, &str_classes, sub_indent.string, module, &num_classes); + zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) _extension_class_string, 4, &str_classes, ZSTR_VAL(sub_indent.buf), module, &num_classes); if (num_classes) { string_printf(str, "\n - Classes [%d] {", num_classes); string_append(str, &str_classes); @@ -1190,7 +1144,7 @@ static void _extension_string(string *str, zend_module_entry *module, char *inde } /* }}} */ -static void _zend_extension_string(string *str, zend_extension *extension, char *indent TSRMLS_DC) /* {{{ */ +static void _zend_extension_string(string *str, zend_extension *extension, char *indent) /* {{{ */ { string_printf(str, "%sZend Extension [ %s ", indent, extension->name); @@ -1226,69 +1180,67 @@ 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 TSRMLS_DC) +PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object) { reflection_object *intern; - zval *name; + zval name; - MAKE_STD_ZVAL(name); - ZVAL_STRINGL(name, ce->name, ce->name_length, 1); - reflection_instantiate(reflection_class_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + ZVAL_STR_COPY(&name, ce->name); + reflection_instantiate(reflection_class_ptr, object); + intern = Z_REFLECTION_P(object); intern->ptr = ce; intern->ref_type = REF_TYPE_OTHER; intern->ce = ce; - reflection_update_property(object, "name", name); + reflection_update_property(object, "name", &name); } /* }}} */ /* {{{ reflection_extension_factory */ -static void reflection_extension_factory(zval *object, const char *name_str TSRMLS_DC) +static void reflection_extension_factory(zval *object, const char *name_str) { reflection_object *intern; - zval *name; - int name_len = strlen(name_str); - char *lcname; + zval name; + size_t name_len = strlen(name_str); + zend_string *lcname; struct _zend_module_entry *module; - ALLOCA_FLAG(use_heap) - lcname = do_alloca(name_len + 1, use_heap); - zend_str_tolower_copy(lcname, name_str, name_len); - if (zend_hash_find(&module_registry, lcname, name_len + 1, (void **)&module) == FAILURE) { - free_alloca(lcname, use_heap); + 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); + if (!module) { return; } - free_alloca(lcname, use_heap); - reflection_instantiate(reflection_extension_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - MAKE_STD_ZVAL(name); - ZVAL_STRINGL(name, module->name, name_len, 1); + reflection_instantiate(reflection_extension_ptr, object); + intern = Z_REFLECTION_P(object); + ZVAL_STRINGL(&name, module->name, name_len); intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; - reflection_update_property(object, "name", name); + reflection_update_property(object, "name", &name); } /* }}} */ /* {{{ reflection_parameter_factory */ -static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zend_uint offset, zend_uint required, zval *object TSRMLS_DC) +static void reflection_parameter_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, uint32_t offset, uint32_t required, zval *object) { reflection_object *intern; parameter_reference *reference; - zval *name; + zval name; - if (closure_object) { - Z_ADDREF_P(closure_object); - } - MAKE_STD_ZVAL(name); if (arg_info->name) { - ZVAL_STRINGL(name, arg_info->name, arg_info->name_len, 1); + if (fptr->type == ZEND_INTERNAL_FUNCTION && + !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { + ZVAL_STRING(&name, ((zend_internal_arg_info*)arg_info)->name); + } else { + ZVAL_STR_COPY(&name, arg_info->name); + } } else { - ZVAL_NULL(name); + ZVAL_NULL(&name); } - reflection_instantiate(reflection_parameter_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + reflection_instantiate(reflection_parameter_ptr, object); + intern = Z_REFLECTION_P(object); reference = (parameter_reference*) emalloc(sizeof(parameter_reference)); reference->arg_info = arg_info; reference->offset = offset; @@ -1297,76 +1249,98 @@ static void reflection_parameter_factory(zend_function *fptr, zval *closure_obje intern->ptr = reference; intern->ref_type = REF_TYPE_PARAMETER; intern->ce = fptr->common.scope; - intern->obj = closure_object; - reflection_update_property(object, "name", name); + if (closure_object) { + Z_ADDREF_P(closure_object); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + } + reflection_update_property(object, "name", &name); } /* }}} */ -/* {{{ reflection_function_factory */ -static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object TSRMLS_DC) +/* {{{ reflection_type_factory */ +static void reflection_type_factory(zend_function *fptr, zval *closure_object, struct _zend_arg_info *arg_info, zval *object) { reflection_object *intern; - zval *name; + type_reference *reference; + reflection_instantiate(reflection_type_ptr, object); + intern = Z_REFLECTION_P(object); + reference = (type_reference*) emalloc(sizeof(type_reference)); + reference->arg_info = arg_info; + reference->fptr = fptr; + intern->ptr = reference; + intern->ref_type = REF_TYPE_TYPE; + intern->ce = fptr->common.scope; if (closure_object) { Z_ADDREF_P(closure_object); + ZVAL_COPY_VALUE(&intern->obj, closure_object); } - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, function->common.function_name, 1); +} +/* }}} */ + +/* {{{ reflection_function_factory */ +static void reflection_function_factory(zend_function *function, zval *closure_object, zval *object) +{ + reflection_object *intern; + zval name; + + ZVAL_STR_COPY(&name, function->common.function_name); - reflection_instantiate(reflection_function_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + reflection_instantiate(reflection_function_ptr, object); + intern = Z_REFLECTION_P(object); intern->ptr = function; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = NULL; - intern->obj = closure_object; - reflection_update_property(object, "name", name); + if (closure_object) { + Z_ADDREF_P(closure_object); + ZVAL_COPY_VALUE(&intern->obj, closure_object); + } + reflection_update_property(object, "name", &name); } /* }}} */ /* {{{ reflection_method_factory */ -static void reflection_method_factory(zend_class_entry *ce, zend_function *method, zval *closure_object, zval *object TSRMLS_DC) +static void reflection_method_factory(zend_class_entry *ce, zend_function *method, zval *closure_object, zval *object) { reflection_object *intern; - zval *name; - zval *classname; - - if (closure_object) { - Z_ADDREF_P(closure_object); - } - MAKE_STD_ZVAL(name); - MAKE_STD_ZVAL(classname); - ZVAL_STRING(name, (method->common.scope && method->common.scope->trait_aliases)? - zend_resolve_method_name(ce, method) : method->common.function_name, 1); - ZVAL_STRINGL(classname, method->common.scope->name, method->common.scope->name_length, 1); - reflection_instantiate(reflection_method_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + zval name; + zval classname; + + ZVAL_STR_COPY(&name, (method->common.scope && method->common.scope->trait_aliases)? + zend_resolve_method_name(ce, method) : method->common.function_name); + ZVAL_STR_COPY(&classname, method->common.scope->name); + reflection_instantiate(reflection_method_ptr, object); + intern = Z_REFLECTION_P(object); intern->ptr = method; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; - intern->obj = closure_object; - reflection_update_property(object, "name", name); - reflection_update_property(object, "class", classname); + if (closure_object) { + 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_property_factory */ -static void reflection_property_factory(zend_class_entry *ce, zend_property_info *prop, zval *object TSRMLS_DC) +static void reflection_property_factory(zend_class_entry *ce, zend_property_info *prop, zval *object) { reflection_object *intern; - zval *name; - zval *classname; + zval name; + zval classname; property_reference *reference; const char *class_name, *prop_name; + size_t prop_name_len; - zend_unmangle_property_name(prop->name, prop->name_length, &class_name, &prop_name); + 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 && zend_hash_find(&tmp_ce->properties_info, prop_name, strlen(prop_name) + 1, (void **) &tmp_info) != SUCCESS) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) == NULL) { ce = tmp_ce; tmp_ce = tmp_ce->parent; } @@ -1378,13 +1352,11 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info } } - MAKE_STD_ZVAL(name); - MAKE_STD_ZVAL(classname); - ZVAL_STRING(name, prop_name, 1); - ZVAL_STRINGL(classname, prop->ce->name, prop->ce->name_length, 1); + ZVAL_STRINGL(&name, prop_name, prop_name_len); + ZVAL_STR_COPY(&classname, prop->ce->name); - reflection_instantiate(reflection_property_ptr, object TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); + reflection_instantiate(reflection_property_ptr, object); + intern = Z_REFLECTION_P(object); reference = (property_reference*) emalloc(sizeof(property_reference)); reference->ce = ce; reference->prop = *prop; @@ -1392,52 +1364,50 @@ static void reflection_property_factory(zend_class_entry *ce, zend_property_info 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(object, "name", &name); + reflection_update_property(object, "class", &classname); } /* }}} */ /* {{{ _reflection_export */ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_ptr, int ctor_argc) { - zval *reflector_ptr; + zval reflector; zval output, *output_ptr = &output; zval *argument_ptr, *argument2_ptr; - zval *retval_ptr, **params[2]; + zval retval, params[2]; int result; int return_output = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; - zval fname; if (ctor_argc == 1) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &argument_ptr, &return_output) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|b", &argument_ptr, &return_output) == FAILURE) { return; } + ZVAL_COPY_VALUE(¶ms[0], argument_ptr); + ZVAL_NULL(¶ms[1]); } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|b", &argument_ptr, &argument2_ptr, &return_output) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz|b", &argument_ptr, &argument2_ptr, &return_output) == FAILURE) { return; } + ZVAL_COPY_VALUE(¶ms[0], argument_ptr); + ZVAL_COPY_VALUE(¶ms[1], argument2_ptr); } - INIT_PZVAL(&output); - /* Create object */ - MAKE_STD_ZVAL(reflector_ptr); - if (object_and_properties_init(reflector_ptr, ce_ptr, NULL) == FAILURE) { + if (object_and_properties_init(&reflector, ce_ptr, NULL) == FAILURE) { _DO_THROW("Could not create reflector"); } /* Call __construct() */ - params[0] = &argument_ptr; - params[1] = &argument2_ptr; fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = reflector_ptr; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = Z_OBJ(reflector); + fci.retval = &retval; fci.param_count = ctor_argc; fci.params = params; fci.no_separation = 1; @@ -1445,54 +1415,53 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c fcc.initialized = 1; fcc.function_handler = ce_ptr->constructor; fcc.calling_scope = ce_ptr; - fcc.called_scope = Z_OBJCE_P(reflector_ptr); - fcc.object_ptr = reflector_ptr; + fcc.called_scope = Z_OBJCE(reflector); + fcc.object = Z_OBJ(reflector); - result = zend_call_function(&fci, &fcc TSRMLS_CC); + result = zend_call_function(&fci, &fcc); - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } + zval_ptr_dtor(&retval); if (EG(exception)) { - zval_ptr_dtor(&reflector_ptr); + zval_ptr_dtor(&reflector); return; } if (result == FAILURE) { - zval_ptr_dtor(&reflector_ptr); + zval_ptr_dtor(&reflector); _DO_THROW("Could not create reflector"); } /* Call static reflection::export */ ZVAL_BOOL(&output, return_output); - params[0] = &reflector_ptr; - params[1] = &output_ptr; + ZVAL_COPY_VALUE(¶ms[0], &reflector); + ZVAL_COPY_VALUE(¶ms[1], output_ptr); - ZVAL_STRINGL(&fname, "reflection::export", sizeof("reflection::export") - 1, 0); + ZVAL_STRINGL(&fci.function_name, "reflection::export", sizeof("reflection::export") - 1); fci.function_table = &reflection_ptr->function_table; - fci.function_name = &fname; - fci.object_ptr = NULL; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = NULL; + fci.retval = &retval; fci.param_count = 2; fci.params = params; fci.no_separation = 1; - result = zend_call_function(&fci, NULL TSRMLS_CC); + result = zend_call_function(&fci, NULL); + + zval_ptr_dtor(&fci.function_name); if (result == FAILURE && EG(exception) == NULL) { - zval_ptr_dtor(&reflector_ptr); - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&reflector); + zval_ptr_dtor(&retval); _DO_THROW("Could not execute reflection::export()"); } if (return_output) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + ZVAL_COPY_VALUE(return_value, &retval); } else { - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&retval); } /* Destruct reflector which is no longer needed */ - zval_ptr_dtor(&reflector_ptr); + zval_ptr_dtor(&reflector); } /* }}} */ @@ -1502,17 +1471,17 @@ static parameter_reference *_reflection_param_get_default_param(INTERNAL_FUNCTIO reflection_object *intern; parameter_reference *param; - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); - if (intern == NULL || intern->ptr == NULL) { - if (EG(exception) && Z_OBJCE_P(EG(exception)) == reflection_exception_ptr) { + intern = Z_REFLECTION_P(getThis()); + if (intern->ptr == NULL) { + if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { return NULL; } - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the reflection object"); + php_error_docref(NULL, E_ERROR, "Internal error: Failed to retrieve the reflection object"); } param = intern->ptr; if (param->fptr->type != ZEND_USER_FUNCTION) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Cannot determine default value for internal functions"); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Cannot determine default value for internal functions"); return NULL; } @@ -1531,7 +1500,7 @@ static zend_op *_reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAMETERS precv = _get_recv_op((zend_op_array*)param->fptr, param->offset); if (!precv || precv->opcode != ZEND_RECV_INIT || precv->op2_type == IS_UNUSED) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Internal error: Failed to retrieve the default value"); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Internal error: Failed to retrieve the default value"); return NULL; } @@ -1551,17 +1520,19 @@ ZEND_METHOD(reflection, __clone) Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection, export) { - zval *object, fname, *retval_ptr; + zval *object, fname, retval; int result; zend_bool return_output = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &object, reflector_ptr, &return_output) == FAILURE) { - return; - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_OBJECT_OF_CLASS(object, reflector_ptr) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(return_output) + ZEND_PARSE_PARAMETERS_END(); /* Invoke the __toString() method */ - ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1, 1); - result= call_user_function_ex(NULL, &object, &fname, &retval_ptr, 0, NULL, 0, NULL TSRMLS_CC); + ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring") - 1); + result= call_user_function_ex(NULL, object, &fname, &retval, 0, NULL, 0, NULL); zval_dtor(&fname); if (result == FAILURE) { @@ -1569,18 +1540,18 @@ ZEND_METHOD(reflection, export) /* Returns from this function */ } - if (!retval_ptr) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::__toString() did not return anything", Z_OBJCE_P(object)->name); + if (Z_TYPE(retval) == IS_UNDEF) { + php_error_docref(NULL, E_WARNING, "%s::__toString() did not return anything", ZSTR_VAL(Z_OBJCE_P(object)->name)); RETURN_FALSE; } if (return_output) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + ZVAL_COPY_VALUE(return_value, &retval); } else { /* No need for _r variant, return of __toString should always be a string */ - zend_print_zval(retval_ptr, 0); + zend_print_zval(&retval, 0); zend_printf("\n"); - zval_ptr_dtor(&retval_ptr); + zval_ptr_dtor(&retval); } } /* }}} */ @@ -1589,39 +1560,39 @@ ZEND_METHOD(reflection, export) Returns an array of modifier names */ ZEND_METHOD(reflection, getModifierNames) { - long modifiers; + zend_long modifiers; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &modifiers) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &modifiers) == FAILURE) { return; } array_init(return_value); if (modifiers & (ZEND_ACC_ABSTRACT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) { - add_next_index_stringl(return_value, "abstract", sizeof("abstract")-1, 1); + add_next_index_stringl(return_value, "abstract", sizeof("abstract")-1); } - if (modifiers & (ZEND_ACC_FINAL | ZEND_ACC_FINAL_CLASS)) { - add_next_index_stringl(return_value, "final", sizeof("final")-1, 1); + if (modifiers & ZEND_ACC_FINAL) { + add_next_index_stringl(return_value, "final", sizeof("final")-1); } if (modifiers & ZEND_ACC_IMPLICIT_PUBLIC) { - add_next_index_stringl(return_value, "public", sizeof("public")-1, 1); + add_next_index_stringl(return_value, "public", sizeof("public")-1); } /* These are mutually exclusive */ switch (modifiers & ZEND_ACC_PPP_MASK) { case ZEND_ACC_PUBLIC: - add_next_index_stringl(return_value, "public", sizeof("public")-1, 1); + add_next_index_stringl(return_value, "public", sizeof("public")-1); break; case ZEND_ACC_PRIVATE: - add_next_index_stringl(return_value, "private", sizeof("private")-1, 1); + add_next_index_stringl(return_value, "private", sizeof("private")-1); break; case ZEND_ACC_PROTECTED: - add_next_index_stringl(return_value, "protected", sizeof("protected")-1, 1); + add_next_index_stringl(return_value, "protected", sizeof("protected")-1); break; } if (modifiers & ZEND_ACC_STATIC) { - add_next_index_stringl(return_value, "static", sizeof("static")-1, 1); + add_next_index_stringl(return_value, "static", sizeof("static")-1); } } /* }}} */ @@ -1638,26 +1609,25 @@ ZEND_METHOD(reflection_function, export) Constructor. Throws an Exception in case the given function does not exist */ ZEND_METHOD(reflection_function, __construct) { - zval *name; + zval name; zval *object; zval *closure = NULL; - char *lcname; + char *lcname, *nsname; reflection_object *intern; zend_function *fptr; char *name_str; - int name_len; + size_t name_len; object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O", &closure, zend_ce_closure) == SUCCESS) { - fptr = (zend_function*)zend_get_closure_method_def(closure TSRMLS_CC); + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) { + fptr = (zend_function*)zend_get_closure_method_def(closure); Z_ADDREF_P(closure); - } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == SUCCESS) { - char *nsname; + } else { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { + return; + } lcname = zend_str_tolower_dup(name_str, name_len); @@ -1668,23 +1638,24 @@ ZEND_METHOD(reflection_function, __construct) name_len--; } - if (zend_hash_find(EG(function_table), nsname, name_len + 1, (void **)&fptr) == FAILURE) { + if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { efree(lcname); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Function %s() does not exist", name_str); return; } efree(lcname); - } else { - return; } - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, fptr->common.function_name, 1); - reflection_update_property(object, "name", name); + ZVAL_STR_COPY(&name, fptr->common.function_name); + reflection_update_property(object, "name", &name); intern->ptr = fptr; intern->ref_type = REF_TYPE_FUNCTION; - intern->obj = closure; + if (closure) { + ZVAL_COPY_VALUE(&intern->obj, closure); + } else { + ZVAL_UNDEF(&intern->obj); + } intern->ce = NULL; } /* }}} */ @@ -1702,8 +1673,8 @@ ZEND_METHOD(reflection_function, __toString) } GET_REFLECTION_OBJECT_PTR(fptr); string_init(&str); - _function_string(&str, fptr, intern->ce, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _function_string(&str, fptr, intern->ce, ""); + RETURN_NEW_STR(str.buf); } /* }}} */ @@ -1714,7 +1685,7 @@ ZEND_METHOD(reflection_function, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); } /* }}} */ @@ -1738,17 +1709,16 @@ ZEND_METHOD(reflection_function, isClosure) ZEND_METHOD(reflection_function, getClosureThis) { reflection_object *intern; - zend_function *fptr; zval* closure_this; if (zend_parse_parameters_none() == FAILURE) { return; } - GET_REFLECTION_OBJECT_PTR(fptr); - if (intern->obj) { - closure_this = zend_get_closure_this_ptr(intern->obj TSRMLS_CC); - if (closure_this) { - RETURN_ZVAL(closure_this, 1, 0); + GET_REFLECTION_OBJECT(); + if (!Z_ISUNDEF(intern->obj)) { + closure_this = zend_get_closure_this_ptr(&intern->obj); + if (!Z_ISUNDEF_P(closure_this)) { + ZVAL_COPY(return_value, closure_this); } } } @@ -1759,17 +1729,16 @@ ZEND_METHOD(reflection_function, getClosureThis) ZEND_METHOD(reflection_function, getClosureScopeClass) { reflection_object *intern; - zend_function *fptr; const zend_function *closure_func; if (zend_parse_parameters_none() == FAILURE) { return; } - GET_REFLECTION_OBJECT_PTR(fptr); - if (intern->obj) { - closure_func = zend_get_closure_method_def(intern->obj TSRMLS_CC); + GET_REFLECTION_OBJECT(); + if (!Z_ISUNDEF(intern->obj)) { + closure_func = zend_get_closure_method_def(&intern->obj); if (closure_func && closure_func->common.scope) { - zend_reflection_class_factory(closure_func->common.scope, return_value TSRMLS_CC); + zend_reflection_class_factory(closure_func->common.scope, return_value); } } } @@ -1787,11 +1756,15 @@ ZEND_METHOD(reflection_function, getClosure) } GET_REFLECTION_OBJECT_PTR(fptr); - zend_create_closure(return_value, fptr, NULL, NULL TSRMLS_CC); + if (!Z_ISUNDEF(intern->obj)) { + /* Closures are immutable objects */ + ZVAL_COPY(return_value, &intern->obj); + } else { + zend_create_fake_closure(return_value, fptr, NULL, NULL, NULL); + } } /* }}} */ - /* {{{ proto public bool ReflectionFunction::isInternal() Returns whether this is an internal function */ ZEND_METHOD(reflection_function, isInternal) @@ -1808,7 +1781,7 @@ ZEND_METHOD(reflection_function, isInternal) /* }}} */ /* {{{ proto public bool ReflectionFunction::isUserDefined() - Returns whether this is an user-defined function */ + Returns whether this is a user-defined function */ ZEND_METHOD(reflection_function, isUserDefined) { reflection_object *intern; @@ -1847,7 +1820,7 @@ ZEND_METHOD(reflection_function, getFileName) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION) { - RETURN_STRING(fptr->op_array.filename, 1); + RETURN_STR_COPY(fptr->op_array.filename); } RETURN_FALSE; } @@ -1901,7 +1874,7 @@ ZEND_METHOD(reflection_function, getDocComment) } GET_REFLECTION_OBJECT_PTR(fptr); if (fptr->type == ZEND_USER_FUNCTION && fptr->op_array.doc_comment) { - RETURN_STRINGL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, 1); + RETURN_STR_COPY(fptr->op_array.doc_comment); } RETURN_FALSE; } @@ -1911,9 +1884,9 @@ ZEND_METHOD(reflection_function, getDocComment) Returns an associative array containing this function's static variables and their values */ ZEND_METHOD(reflection_function, getStaticVariables) { - zval *tmp_copy; reflection_object *intern; zend_function *fptr; + zval *val; if (zend_parse_parameters_none() == FAILURE) { return; @@ -1923,8 +1896,18 @@ ZEND_METHOD(reflection_function, getStaticVariables) /* 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) { - zend_hash_apply_with_argument(fptr->op_array.static_variables, (apply_func_arg_t) zval_update_constant_inline_change, fptr->common.scope TSRMLS_CC); - zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); + 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)--; + } + fptr->op_array.static_variables = zend_array_dup(fptr->op_array.static_variables); + } + ZEND_HASH_FOREACH_VAL(fptr->op_array.static_variables, val) { + if (UNEXPECTED(zval_update_constant_ex(val, 1, fptr->common.scope) != SUCCESS)) { + return; + } + } ZEND_HASH_FOREACH_END(); + zend_hash_copy(Z_ARRVAL_P(return_value), fptr->op_array.static_variables, zval_add_ref); } } /* }}} */ @@ -1933,8 +1916,8 @@ ZEND_METHOD(reflection_function, getStaticVariables) Invokes the function */ ZEND_METHOD(reflection_function, invoke) { - zval *retval_ptr; - zval ***params = NULL; + zval retval; + zval *params = NULL; int result, num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -1944,16 +1927,16 @@ ZEND_METHOD(reflection_function, invoke) METHOD_NOTSTATIC(reflection_function_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", ¶ms, &num_args) == FAILURE) { return; } fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = NULL; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = NULL; + fci.retval = &retval; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; @@ -1962,40 +1945,30 @@ ZEND_METHOD(reflection_function, invoke) fcc.function_handler = fptr; fcc.calling_scope = EG(scope); fcc.called_scope = NULL; - fcc.object_ptr = NULL; + fcc.object = NULL; - result = zend_call_function(&fci, &fcc TSRMLS_CC); - - if (num_args) { - efree(params); - } + result = zend_call_function(&fci, &fcc); if (result == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of function %s() failed", fptr->common.function_name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Invocation of function %s() failed", ZSTR_VAL(fptr->common.function_name)); return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ -static int _zval_array_to_c_array(zval **arg, zval ****params TSRMLS_DC) /* {{{ */ -{ - *(*params)++ = arg; - return ZEND_HASH_APPLY_KEEP; -} /* }}} */ - /* {{{ proto public mixed ReflectionFunction::invokeArgs(array args) Invokes the function and pass its arguments as array. */ ZEND_METHOD(reflection_function, invokeArgs) { - zval *retval_ptr; - zval ***params; + zval retval; + zval *params, *val; int result; - int argc; + int i, argc; zend_fcall_info fci; zend_fcall_info_cache fcc; reflection_object *intern; @@ -2005,22 +1978,25 @@ ZEND_METHOD(reflection_function, invokeArgs) METHOD_NOTSTATIC(reflection_function_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", ¶m_array) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", ¶m_array) == FAILURE) { return; } argc = zend_hash_num_elements(Z_ARRVAL_P(param_array)); - params = safe_emalloc(sizeof(zval **), argc, 0); - zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); - params -= argc; + params = safe_emalloc(sizeof(zval), argc, 0); + argc = 0; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(param_array), val) { + ZVAL_COPY(¶ms[argc], val); + argc++; + } ZEND_HASH_FOREACH_END(); fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = NULL; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = NULL; + fci.retval = &retval; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -2029,20 +2005,23 @@ ZEND_METHOD(reflection_function, invokeArgs) fcc.function_handler = fptr; fcc.calling_scope = EG(scope); fcc.called_scope = NULL; - fcc.object_ptr = NULL; + fcc.object = NULL; - result = zend_call_function(&fci, &fcc TSRMLS_CC); + result = zend_call_function(&fci, &fcc); + for (i = 0; i < argc; i++) { + zval_ptr_dtor(¶ms[i]); + } efree(params); if (result == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of function %s() failed", fptr->common.function_name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Invocation of function %s() failed", ZSTR_VAL(fptr->common.function_name)); return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -2067,11 +2046,17 @@ ZEND_METHOD(reflection_function, getNumberOfParameters) { reflection_object *intern; zend_function *fptr; + uint32_t num_args; METHOD_NOTSTATIC(reflection_function_abstract_ptr); GET_REFLECTION_OBJECT_PTR(fptr); - RETURN_LONG(fptr->common.num_args); + num_args = fptr->common.num_args; + if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { + num_args++; + } + + RETURN_LONG(num_args); } /* }}} */ @@ -2095,21 +2080,24 @@ ZEND_METHOD(reflection_function, getParameters) { reflection_object *intern; zend_function *fptr; - zend_uint i; + 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; + num_args = fptr->common.num_args; + if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { + num_args++; + } array_init(return_value); - for (i = 0; i < fptr->common.num_args; i++) { - zval *parameter; + for (i = 0; i < num_args; i++) { + zval parameter; - ALLOC_ZVAL(parameter); - reflection_parameter_factory(_copy_function(fptr TSRMLS_CC), intern->obj, arg_info, i, fptr->common.required_num_args, parameter TSRMLS_CC); - add_next_index_zval(return_value, parameter); + reflection_parameter_factory(_copy_function(fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, arg_info, i, fptr->common.required_num_args, ¶meter); + add_next_index_zval(return_value, ¶meter); arg_info++; } @@ -2133,7 +2121,7 @@ ZEND_METHOD(reflection_function, getExtension) internal = (zend_internal_function *)fptr; if (internal->module) { - reflection_extension_factory(return_value, internal->module->name TSRMLS_CC); + reflection_extension_factory(return_value, internal->module->name); } else { RETURN_NULL(); } @@ -2157,13 +2145,178 @@ ZEND_METHOD(reflection_function, getExtensionName) internal = (zend_internal_function *)fptr; if (internal->module) { - RETURN_STRING(internal->module->name, 1); + RETURN_STRING(internal->module->name); } else { RETURN_FALSE; } } /* }}} */ +/* {{{ proto public void ReflectionGenerator::__construct(object Generator) */ +ZEND_METHOD(reflection_generator, __construct) +{ + zval *generator, *object; + reflection_object *intern; + zend_execute_data *ex; + + object = getThis(); + intern = Z_REFLECTION_P(object); + + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &generator, zend_ce_generator) == FAILURE) { + return; + } + + ex = ((zend_generator *) Z_OBJ_P(generator))->execute_data; + if (!ex) { + zend_throw_exception(NULL, "Cannot create ReflectionGenerator based on a terminated Generator", 0); + return; + } + + intern->ref_type = REF_TYPE_GENERATOR; + ZVAL_COPY(&intern->obj, generator); + intern->ce = zend_ce_generator; +} +/* }}} */ + +#define REFLECTION_CHECK_VALID_GENERATOR(ex) \ + if (!ex) { \ + zend_throw_exception(NULL, "Cannot fetch information from a terminated Generator", 0); \ + return; \ + } + +/* {{{ proto public array ReflectionGenerator::getTrace($options = DEBUG_BACKTRACE_PROVIDE_OBJECT) */ +ZEND_METHOD(reflection_generator, getTrace) +{ + zend_long options = DEBUG_BACKTRACE_PROVIDE_OBJECT; + zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->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; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &options) == FAILURE) { + return; + } + + REFLECTION_CHECK_VALID_GENERATOR(ex) + + root_generator = zend_generator_get_current(generator); + + cur_prev = generator->execute_data->prev_execute_data; + if (generator == root_generator) { + generator->execute_data->prev_execute_data = NULL; + } else { + root_prev = root_generator->execute_data->prev_execute_data; + generator->execute_fake.prev_execute_data = NULL; + root_generator->execute_data->prev_execute_data = &generator->execute_fake; + } + + EG(current_execute_data) = root_generator->execute_data; + zend_fetch_debug_backtrace(return_value, 0, options, 0); + EG(current_execute_data) = ex_backup; + + root_generator->execute_data->prev_execute_data = root_prev; + generator->execute_data->prev_execute_data = cur_prev; +} +/* }}} */ + +/* {{{ proto public int ReflectionGenerator::getExecutingLine() */ +ZEND_METHOD(reflection_generator, getExecutingLine) +{ + zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj); + zend_execute_data *ex = generator->execute_data; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + REFLECTION_CHECK_VALID_GENERATOR(ex) + + ZVAL_LONG(return_value, ex->opline->lineno); +} +/* }}} */ + +/* {{{ proto public string ReflectionGenerator::getExecutingFile() */ +ZEND_METHOD(reflection_generator, getExecutingFile) +{ + zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj); + zend_execute_data *ex = generator->execute_data; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + REFLECTION_CHECK_VALID_GENERATOR(ex) + + ZVAL_STR_COPY(return_value, ex->func->op_array.filename); +} +/* }}} */ + +/* {{{ proto public ReflectionFunctionAbstract ReflectionGenerator::getFunction() */ +ZEND_METHOD(reflection_generator, getFunction) +{ + zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj); + zend_execute_data *ex = generator->execute_data; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + REFLECTION_CHECK_VALID_GENERATOR(ex) + + if (ex->func->common.fn_flags & ZEND_ACC_CLOSURE) { + zval closure; + ZVAL_OBJ(&closure, (zend_object *) ex->func->common.prototype); + 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); + } else { + reflection_function_factory(ex->func, NULL, return_value); + } +} +/* }}} */ + +/* {{{ proto public object ReflectionGenerator::getThis() */ +ZEND_METHOD(reflection_generator, getThis) +{ + zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj); + zend_execute_data *ex = generator->execute_data; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + REFLECTION_CHECK_VALID_GENERATOR(ex) + + if (Z_OBJ(ex->This)) { + ZVAL_COPY(return_value, &ex->This); + } else { + ZVAL_NULL(return_value); + } +} +/* }}} */ + +/* {{{ proto public Generator ReflectionGenerator::getExecutingGenerator() */ +ZEND_METHOD(reflection_generator, getExecutingGenerator) +{ + zend_generator *generator = (zend_generator *) Z_OBJ(Z_REFLECTION_P(getThis())->obj); + zend_execute_data *ex = generator->execute_data; + zend_generator *current; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + REFLECTION_CHECK_VALID_GENERATOR(ex) + + current = zend_generator_get_current(generator); + ++GC_REFCOUNT(¤t->std); + + ZVAL_OBJ(return_value, (zend_object *) current); +} +/* }}} */ + + /* {{{ proto public static mixed ReflectionParameter::export(mixed function, mixed parameter [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_parameter, export) @@ -2177,37 +2330,35 @@ ZEND_METHOD(reflection_parameter, export) ZEND_METHOD(reflection_parameter, __construct) { parameter_reference *ref; - zval *reference, **parameter; + zval *reference, *parameter; zval *object; - zval *name; + zval name; reflection_object *intern; zend_function *fptr; struct _zend_arg_info *arg_info; int position; + uint32_t num_args; zend_class_entry *ce = NULL; zend_bool is_closure = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zZ", &reference, ¶meter) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &reference, ¶meter) == FAILURE) { return; } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); /* First, find the function */ switch (Z_TYPE_P(reference)) { case IS_STRING: { - unsigned int lcname_len; + size_t lcname_len; char *lcname; lcname_len = Z_STRLEN_P(reference); lcname = zend_str_tolower_dup(Z_STRVAL_P(reference), lcname_len); - if (zend_hash_find(EG(function_table), lcname, lcname_len + 1, (void**) &fptr) == FAILURE) { + if ((fptr = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len)) == NULL) { efree(lcname); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Function %s() does not exist", Z_STRVAL_P(reference)); return; } @@ -2217,45 +2368,43 @@ ZEND_METHOD(reflection_parameter, __construct) break; case IS_ARRAY: { - zval **classref; - zval **method; - zend_class_entry **pce; - unsigned int lcname_len; + zval *classref; + zval *method; + size_t lcname_len; char *lcname; - if ((zend_hash_index_find(Z_ARRVAL_P(reference), 0, (void **) &classref) == FAILURE) - || (zend_hash_index_find(Z_ARRVAL_P(reference), 1, (void **) &method) == FAILURE)) + if (((classref =zend_hash_index_find(Z_ARRVAL_P(reference), 0)) == NULL) + || ((method = zend_hash_index_find(Z_ARRVAL_P(reference), 1)) == NULL)) { _DO_THROW("Expected array($object, $method) or array($classname, $method)"); /* returns out of this function */ } - if (Z_TYPE_PP(classref) == IS_OBJECT) { - ce = Z_OBJCE_PP(classref); + if (Z_TYPE_P(classref) == IS_OBJECT) { + ce = Z_OBJCE_P(classref); } else { convert_to_string_ex(classref); - if (zend_lookup_class(Z_STRVAL_PP(classref), Z_STRLEN_PP(classref), &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not exist", Z_STRVAL_PP(classref)); + if ((ce = zend_lookup_class(Z_STR_P(classref))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Class %s does not exist", Z_STRVAL_P(classref)); return; } - ce = *pce; } convert_to_string_ex(method); - lcname_len = Z_STRLEN_PP(method); - lcname = zend_str_tolower_dup(Z_STRVAL_PP(method), lcname_len); - if (ce == zend_ce_closure && Z_TYPE_PP(classref) == IS_OBJECT + lcname_len = Z_STRLEN_P(method); + lcname = zend_str_tolower_dup(Z_STRVAL_P(method), lcname_len); + if (ce == zend_ce_closure && Z_TYPE_P(classref) == IS_OBJECT && (lcname_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lcname, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (fptr = zend_get_closure_invoke_method(*classref TSRMLS_CC)) != NULL) + && (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 (zend_hash_find(&ce->function_table, lcname, lcname_len + 1, (void **) &fptr) == FAILURE) { + not the closure itself */ + } 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 TSRMLS_CC, - "Method %s::%s() does not exist", ce->name, Z_STRVAL_PP(method)); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Method %s::%s() does not exist", ZSTR_VAL(ce->name), Z_STRVAL_P(method)); return; } efree(lcname); @@ -2265,13 +2414,13 @@ ZEND_METHOD(reflection_parameter, __construct) case IS_OBJECT: { ce = Z_OBJCE_P(reference); - if (instanceof_function(ce, zend_ce_closure TSRMLS_CC)) { - fptr = (zend_function *)zend_get_closure_method_def(reference TSRMLS_CC); + if (instanceof_function(ce, zend_ce_closure)) { + fptr = (zend_function *)zend_get_closure_method_def(reference); Z_ADDREF_P(reference); is_closure = 1; - } else if (zend_hash_find(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME), (void **)&fptr) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s() does not exist", ce->name, ZEND_INVOKE_FUNC_NAME); + } else if ((fptr = zend_hash_str_find_ptr(&ce->function_table, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZEND_INVOKE_FUNC_NAME); return; } } @@ -2284,58 +2433,81 @@ ZEND_METHOD(reflection_parameter, __construct) /* Now, search for the parameter */ arg_info = fptr->common.arg_info; - if (Z_TYPE_PP(parameter) == IS_LONG) { - position= Z_LVAL_PP(parameter); - if (position < 0 || (zend_uint)position >= fptr->common.num_args) { - if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { + num_args = fptr->common.num_args; + if (fptr->common.fn_flags & ZEND_ACC_VARIADIC) { + num_args++; + } + if (Z_TYPE_P(parameter) == IS_LONG) { + position= (int)Z_LVAL_P(parameter); + if (position < 0 || (uint32_t)position >= num_args) { + if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - efree((char*)fptr->common.function_name); + zend_string_release(fptr->common.function_name); } - efree(fptr); + zend_free_trampoline(fptr); } if (is_closure) { - zval_ptr_dtor(&reference); + zval_ptr_dtor(reference); } _DO_THROW("The parameter specified by its offset could not be found"); /* returns out of this function */ } } else { - zend_uint i; + uint32_t i; position= -1; convert_to_string_ex(parameter); - for (i = 0; i < fptr->common.num_args; i++) { - if (arg_info[i].name && strcmp(arg_info[i].name, Z_STRVAL_PP(parameter)) == 0) { - position= i; - break; + if (fptr->type == ZEND_INTERNAL_FUNCTION && + !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { + for (i = 0; i < num_args; i++) { + if (arg_info[i].name) { + if (strcmp(((zend_internal_arg_info*)arg_info)[i].name, Z_STRVAL_P(parameter)) == 0) { + position= i; + break; + } + + } + } + } else { + for (i = 0; i < num_args; i++) { + if (arg_info[i].name) { + if (strcmp(ZSTR_VAL(arg_info[i].name), Z_STRVAL_P(parameter)) == 0) { + position= i; + break; + } + } } } if (position == -1) { - if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) { + if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { if (fptr->type != ZEND_OVERLOADED_FUNCTION) { - efree((char*)fptr->common.function_name); + zend_string_release(fptr->common.function_name); } - efree(fptr); + zend_free_trampoline(fptr); } if (is_closure) { - zval_ptr_dtor(&reference); + zval_ptr_dtor(reference); } _DO_THROW("The parameter specified by its name could not be found"); /* returns out of this function */ } } - MAKE_STD_ZVAL(name); if (arg_info[position].name) { - ZVAL_STRINGL(name, arg_info[position].name, arg_info[position].name_len, 1); + if (fptr->type == ZEND_INTERNAL_FUNCTION && + !(fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { + ZVAL_STRING(&name, ((zend_internal_arg_info*)arg_info)[position].name); + } else { + ZVAL_STR_COPY(&name, arg_info[position].name); + } } else { - ZVAL_NULL(name); + ZVAL_NULL(&name); } - reflection_update_property(object, "name", name); + reflection_update_property(object, "name", &name); ref = (parameter_reference*) emalloc(sizeof(parameter_reference)); ref->arg_info = &arg_info[position]; - ref->offset = (zend_uint)position; + ref->offset = (uint32_t)position; ref->required = fptr->common.required_num_args; ref->fptr = fptr; /* TODO: copy fptr */ @@ -2343,7 +2515,7 @@ ZEND_METHOD(reflection_parameter, __construct) intern->ref_type = REF_TYPE_PARAMETER; intern->ce = ce; if (reference && is_closure) { - intern->obj = reference; + ZVAL_COPY_VALUE(&intern->obj, reference); } } /* }}} */ @@ -2361,9 +2533,10 @@ ZEND_METHOD(reflection_parameter, __toString) } GET_REFLECTION_OBJECT_PTR(param); string_init(&str); - _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _parameter_string(&str, param->fptr, param->arg_info, param->offset, param->required, ""); + RETURN_NEW_STR(str.buf); } + /* }}} */ /* {{{ proto public string ReflectionParameter::getName() @@ -2373,7 +2546,7 @@ ZEND_METHOD(reflection_parameter, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); } /* }}} */ @@ -2390,15 +2563,15 @@ ZEND_METHOD(reflection_parameter, getDeclaringFunction) GET_REFLECTION_OBJECT_PTR(param); if (!param->fptr->common.scope) { - reflection_function_factory(_copy_function(param->fptr TSRMLS_CC), intern->obj, return_value TSRMLS_CC); + reflection_function_factory(_copy_function(param->fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, return_value); } else { - reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr TSRMLS_CC), intern->obj, return_value TSRMLS_CC); + reflection_method_factory(param->fptr->common.scope, _copy_function(param->fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, return_value); } } /* }}} */ /* {{{ proto public ReflectionClass|NULL ReflectionParameter::getDeclaringClass() - Returns in which class this parameter is defined (not the typehint of the parameter) */ + Returns in which class this parameter is defined (not the type of the parameter) */ ZEND_METHOD(reflection_parameter, getDeclaringClass) { reflection_object *intern; @@ -2410,7 +2583,7 @@ ZEND_METHOD(reflection_parameter, getDeclaringClass) GET_REFLECTION_OBJECT_PTR(param); if (param->fptr->common.scope) { - zend_reflection_class_factory(param->fptr->common.scope, return_value TSRMLS_CC); + zend_reflection_class_factory(param->fptr->common.scope, return_value); } } /* }}} */ @@ -2421,7 +2594,7 @@ ZEND_METHOD(reflection_parameter, getClass) { reflection_object *intern; parameter_reference *param; - zend_class_entry **pce, *ce; + zend_class_entry *ce; if (zend_parse_parameters_none() == FAILURE) { return; @@ -2441,37 +2614,96 @@ ZEND_METHOD(reflection_parameter, getClass) * TODO: Think about moving these checks to the compiler or some sort of * lint-mode. */ - if (0 == zend_binary_strcasecmp(param->arg_info->class_name, param->arg_info->class_name_len, "self", sizeof("self")- 1)) { + const char *class_name; + size_t class_name_len; + + if (param->fptr->type == ZEND_INTERNAL_FUNCTION && + !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { + class_name = ((zend_internal_arg_info*)param->arg_info)->class_name; + class_name_len = strlen(class_name); + } else { + class_name = ZSTR_VAL(param->arg_info->class_name); + class_name_len = ZSTR_LEN(param->arg_info->class_name); + } + if (0 == zend_binary_strcasecmp(class_name, class_name_len, "self", sizeof("self")- 1)) { ce = param->fptr->common.scope; if (!ce) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Parameter uses 'self' as type hint but function is not a class member!"); return; } - pce= &ce; - } else if (0 == zend_binary_strcasecmp(param->arg_info->class_name, param->arg_info->class_name_len, "parent", sizeof("parent")- 1)) { + } else if (0 == zend_binary_strcasecmp(class_name, class_name_len, "parent", sizeof("parent")- 1)) { ce = param->fptr->common.scope; if (!ce) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Parameter uses 'parent' as type hint but function is not a class member!"); return; } if (!ce->parent) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Parameter uses 'parent' as type hint although class does not have a parent!"); return; } - pce= &ce->parent; - } else if (zend_lookup_class(param->arg_info->class_name, param->arg_info->class_name_len, &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not exist", param->arg_info->class_name); - return; + ce = ce->parent; + } else { + if (param->fptr->type == ZEND_INTERNAL_FUNCTION && + !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { + zend_string *name = zend_string_init(class_name, class_name_len, 0); + ce = zend_lookup_class(name); + zend_string_release(name); + } else { + ce = zend_lookup_class(param->arg_info->class_name); + } + if (!ce) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Class %s does not exist", class_name); + return; + } } - zend_reflection_class_factory(*pce, return_value TSRMLS_CC); + zend_reflection_class_factory(ce, return_value); } } /* }}} */ +/* {{{ proto public bool ReflectionParameter::hasType() + Returns whether parameter has a type */ +ZEND_METHOD(reflection_parameter, hasType) +{ + reflection_object *intern; + parameter_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->type_hint != 0); +} +/* }}} */ + +/* {{{ proto public ReflectionType ReflectionParameter::getType() + Returns the type associated with the parameter */ +ZEND_METHOD(reflection_parameter, getType) +{ + reflection_object *intern; + parameter_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + if (((param->fptr->type == ZEND_INTERNAL_FUNCTION && + !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) ? + ((zend_internal_arg_info*)param->arg_info)->type_hint : + param->arg_info->type_hint) == 0) + { + RETURN_NULL(); + } + reflection_type_factory(_copy_function(param->fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, param->arg_info, return_value); +} +/* }}} */ + /* {{{ proto public bool ReflectionParameter::isArray() Returns whether parameter MUST be an array */ ZEND_METHOD(reflection_parameter, isArray) @@ -2617,7 +2849,6 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) { parameter_reference *param; zend_op *precv; - zend_class_entry *old_scope; if (zend_parse_parameters_none() == FAILURE) { return; @@ -2633,24 +2864,16 @@ ZEND_METHOD(reflection_parameter, getDefaultValue) return; } - *return_value = *precv->op2.zv; - INIT_PZVAL(return_value); - if (!IS_CONSTANT_TYPE(Z_TYPE_P(return_value))) { - if (Z_TYPE_P(return_value) != IS_ARRAY) { - zval_copy_ctor(return_value); - } else { - HashTable *ht; + ZVAL_COPY_VALUE(return_value, RT_CONSTANT(¶m->fptr->op_array, precv->op2)); + if (Z_CONSTANT_P(return_value)) { + zend_class_entry *old_scope = EG(scope); - ALLOC_HASHTABLE(ht); - zend_hash_init(ht, zend_hash_num_elements(Z_ARRVAL_P(return_value)), NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(ht, Z_ARRVAL_P(return_value), (copy_ctor_func_t) reflection_zval_deep_copy, NULL, sizeof(zval *)); - Z_ARRVAL_P(return_value) = ht; - } + EG(scope) = param->fptr->common.scope; + zval_update_constant_ex(return_value, 0, NULL); + EG(scope) = old_scope; + } else { + zval_copy_ctor(return_value); } - old_scope = EG(scope); - EG(scope) = param->fptr->common.scope; - zval_update_constant_ex(&return_value, 0, NULL TSRMLS_CC); - EG(scope) = old_scope; } /* }}} */ @@ -2671,7 +2894,7 @@ ZEND_METHOD(reflection_parameter, isDefaultValueConstant) } precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); - if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { + if (precv && Z_TYPE_P(RT_CONSTANT(¶m->fptr->op_array, precv->op2)) == IS_CONSTANT) { RETURN_TRUE; } @@ -2696,8 +2919,8 @@ ZEND_METHOD(reflection_parameter, getDefaultValueConstantName) } precv = _reflection_param_get_default_precv(INTERNAL_FUNCTION_PARAM_PASSTHRU, param); - if (precv && (Z_TYPE_P(precv->op2.zv) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) { - RETURN_STRINGL(Z_STRVAL_P(precv->op2.zv), Z_STRLEN_P(precv->op2.zv), 1); + 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))); } } /* }}} */ @@ -2718,6 +2941,68 @@ ZEND_METHOD(reflection_parameter, isVariadic) } /* }}} */ +/* {{{ proto public bool ReflectionType::allowsNull() + Returns whether parameter MAY be null */ +ZEND_METHOD(reflection_type, allowsNull) +{ + reflection_object *intern; + type_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->allow_null); +} +/* }}} */ + +/* {{{ proto public bool ReflectionType::isBuiltin() + Returns whether parameter is a builtin type */ +ZEND_METHOD(reflection_type, isBuiltin) +{ + reflection_object *intern; + type_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + RETVAL_BOOL(param->arg_info->type_hint != IS_OBJECT); +} +/* }}} */ + +/* {{{ proto public string ReflectionType::__toString() + Return the text of the type hint */ +ZEND_METHOD(reflection_type, __toString) +{ + reflection_object *intern; + type_reference *param; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(param); + + switch (param->arg_info->type_hint) { + case IS_ARRAY: RETURN_STRINGL("array", sizeof("array") - 1); + case IS_CALLABLE: RETURN_STRINGL("callable", sizeof("callable") - 1); + case IS_OBJECT: + if (param->fptr->type == ZEND_INTERNAL_FUNCTION && + !(param->fptr->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) { + RETURN_STRING(((zend_internal_arg_info*)param->arg_info)->class_name); + } + RETURN_STR_COPY(param->arg_info->class_name); + case IS_STRING: RETURN_STRINGL("string", sizeof("string") - 1); + case _IS_BOOL: RETURN_STRINGL("bool", sizeof("bool") - 1); + case IS_LONG: RETURN_STRINGL("int", sizeof("int") - 1); + case IS_DOUBLE: RETURN_STRINGL("float", sizeof("float") - 1); + EMPTY_SWITCH_DEFAULT_CASE() + } +} +/* }}} */ + /* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */ ZEND_METHOD(reflection_method, export) @@ -2730,28 +3015,29 @@ ZEND_METHOD(reflection_method, export) Constructor. Throws an Exception in case the given method does not exist */ ZEND_METHOD(reflection_method, __construct) { - zval *name, *classname; + zval name, *classname; zval *object, *orig_obj; reflection_object *intern; char *lcname; - zend_class_entry **pce; zend_class_entry *ce; zend_function *mptr; char *name_str, *tmp; - int name_len, tmp_len; + size_t name_len, tmp_len; zval ztmp; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "zs", &classname, &name_str, &name_len) == FAILURE) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) { + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { return; } + if ((tmp = strstr(name_str, "::")) == NULL) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invalid method name %s", name_str); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Invalid method name %s", name_str); return; } classname = &ztmp; tmp_len = tmp - name_str; - ZVAL_STRINGL(classname, name_str, tmp_len, 1); + ZVAL_STRINGL(classname, name_str, tmp_len); name_len = name_len - (tmp_len + 2); name_str = tmp + 2; orig_obj = NULL; @@ -2762,23 +3048,19 @@ ZEND_METHOD(reflection_method, __construct) } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); /* Find the class entry */ switch (Z_TYPE_P(classname)) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not exist", Z_STRVAL_P(classname)); if (classname == &ztmp) { zval_dtor(&ztmp); } return; } - ce = *pce; break; case IS_OBJECT: @@ -2801,25 +3083,21 @@ ZEND_METHOD(reflection_method, __construct) if (ce == zend_ce_closure && orig_obj && (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 TSRMLS_CC)) != NULL) + && (mptr = zend_get_closure_invoke_method(Z_OBJ_P(orig_obj))) != NULL) { /* do nothing, mptr already set */ - } else if (zend_hash_find(&ce->function_table, lcname, name_len + 1, (void **) &mptr) == FAILURE) { + } 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 TSRMLS_CC, - "Method %s::%s() does not exist", ce->name, name_str); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Method %s::%s() does not exist", ZSTR_VAL(ce->name), name_str); return; } efree(lcname); - MAKE_STD_ZVAL(classname); - ZVAL_STRINGL(classname, mptr->common.scope->name, mptr->common.scope->name_length, 1); - - reflection_update_property(object, "class", classname); - - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, mptr->common.function_name, 1); - reflection_update_property(object, "name", name); + ZVAL_STR_COPY(&name, mptr->common.scope->name); + reflection_update_property(object, "class", &name); + ZVAL_STR_COPY(&name, mptr->common.function_name); + reflection_update_property(object, "name", &name); intern->ptr = mptr; intern->ref_type = REF_TYPE_FUNCTION; intern->ce = ce; @@ -2839,8 +3117,8 @@ ZEND_METHOD(reflection_method, __toString) } GET_REFLECTION_OBJECT_PTR(mptr); string_init(&str); - _function_string(&str, mptr, intern->ce, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _function_string(&str, mptr, intern->ce, ""); + RETURN_NEW_STR(str.buf); } /* }}} */ @@ -2856,24 +3134,24 @@ ZEND_METHOD(reflection_method, getClosure) GET_REFLECTION_OBJECT_PTR(mptr); if (mptr->common.fn_flags & ZEND_ACC_STATIC) { - zend_create_closure(return_value, mptr, mptr->common.scope, NULL TSRMLS_CC); + zend_create_fake_closure(return_value, mptr, mptr->common.scope, mptr->common.scope, NULL); } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) { return; } - if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope TSRMLS_CC)) { + if (!instanceof_function(Z_OBJCE_P(obj), mptr->common.scope)) { _DO_THROW("Given object is not an instance of the class this method was declared in"); /* Returns from this function */ } /* This is an original closure object and __invoke is to be called. */ - if (Z_OBJCE_P(obj) == zend_ce_closure && mptr->type == ZEND_INTERNAL_FUNCTION && - (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) + if (Z_OBJCE_P(obj) == zend_ce_closure && + (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { - RETURN_ZVAL(obj, 1, 0); + ZVAL_COPY(return_value, obj); } else { - zend_create_closure(return_value, mptr, mptr->common.scope, obj TSRMLS_CC); + zend_create_fake_closure(return_value, mptr, mptr->common.scope, Z_OBJCE_P(obj), obj); } } } @@ -2883,9 +3161,9 @@ ZEND_METHOD(reflection_method, getClosure) Invokes the method. */ ZEND_METHOD(reflection_method, invoke) { - zval *retval_ptr; - zval ***params = NULL; - zval *object_ptr; + zval retval; + zval *params = NULL; + zend_object *object; reflection_object *intern; zend_function *mptr; int result, num_args = 0; @@ -2902,20 +3180,20 @@ ZEND_METHOD(reflection_method, invoke) && intern->ignore_visibility == 0) { if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Trying to invoke abstract method %s::%s()", - mptr->common.scope->name, mptr->common.function_name); + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); } else { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + 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", - mptr->common.scope->name, mptr->common.function_name, - Z_OBJCE_P(getThis())->name); + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name), + ZSTR_VAL(Z_OBJCE_P(getThis())->name)); } return; } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶ms, &num_args) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", ¶ms, &num_args) == FAILURE) { return; } @@ -2926,34 +3204,30 @@ ZEND_METHOD(reflection_method, invoke) * Else, we verify that the given object is an instance of the class. */ if (mptr->common.fn_flags & ZEND_ACC_STATIC) { - object_ptr = NULL; + object = NULL; obj_ce = mptr->common.scope; } else { - if (Z_TYPE_PP(params[0]) != IS_OBJECT) { - efree(params); + if (Z_TYPE(params[0]) != IS_OBJECT) { _DO_THROW("Non-object passed to Invoke()"); /* Returns from this function */ } - obj_ce = Z_OBJCE_PP(params[0]); + obj_ce = Z_OBJCE(params[0]); - if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) { - if (params) { - efree(params); - } + if (!instanceof_function(obj_ce, mptr->common.scope)) { _DO_THROW("Given object is not an instance of the class this method was declared in"); /* Returns from this function */ } - object_ptr = *params[0]; + object = Z_OBJ(params[0]); } fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = object_ptr; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = object; + fci.retval = &retval; fci.param_count = num_args - 1; fci.params = params + 1; fci.no_separation = 1; @@ -2962,22 +3236,18 @@ ZEND_METHOD(reflection_method, invoke) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - fcc.object_ptr = object_ptr; + fcc.object = object; - result = zend_call_function(&fci, &fcc TSRMLS_CC); - - if (params) { - efree(params); - } + result = zend_call_function(&fci, &fcc); if (result == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Invocation of method %s::%s() failed", ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -2986,12 +3256,11 @@ ZEND_METHOD(reflection_method, invoke) Invokes the function and pass its arguments as array. */ ZEND_METHOD(reflection_method, invokeArgs) { - zval *retval_ptr; - zval ***params; - zval *object; + zval retval; + zval *params, *val, *object; reflection_object *intern; zend_function *mptr; - int argc; + int i, argc; int result; zend_fcall_info fci; zend_fcall_info_cache fcc; @@ -3002,7 +3271,7 @@ ZEND_METHOD(reflection_method, invokeArgs) GET_REFLECTION_OBJECT_PTR(mptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o!a", &object, ¶m_array) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o!a", &object, ¶m_array) == FAILURE) { return; } @@ -3011,24 +3280,27 @@ ZEND_METHOD(reflection_method, invokeArgs) && intern->ignore_visibility == 0) { if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Trying to invoke abstract method %s::%s()", - mptr->common.scope->name, mptr->common.function_name); + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); } else { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + 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", - mptr->common.scope->name, mptr->common.function_name, - Z_OBJCE_P(getThis())->name); + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name), + ZSTR_VAL(Z_OBJCE_P(getThis())->name)); } return; } argc = zend_hash_num_elements(Z_ARRVAL_P(param_array)); - params = safe_emalloc(sizeof(zval **), argc, 0); - zend_hash_apply_with_argument(Z_ARRVAL_P(param_array), (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); - params -= argc; + params = safe_emalloc(sizeof(zval), argc, 0); + argc = 0; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(param_array), val) { + ZVAL_COPY(¶ms[argc], val); + argc++; + } ZEND_HASH_FOREACH_END(); /* In case this is a static method, we should'nt pass an object_ptr * (which is used as calling context aka $this). We can thus ignore the @@ -3042,15 +3314,15 @@ ZEND_METHOD(reflection_method, invokeArgs) } else { if (!object) { efree(params); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Trying to invoke non static method %s::%s() without an object", - mptr->common.scope->name, mptr->common.function_name); + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); return; } obj_ce = Z_OBJCE_P(object); - if (!instanceof_function(obj_ce, mptr->common.scope TSRMLS_CC)) { + if (!instanceof_function(obj_ce, mptr->common.scope)) { efree(params); _DO_THROW("Given object is not an instance of the class this method was declared in"); /* Returns from this function */ @@ -3059,10 +3331,10 @@ ZEND_METHOD(reflection_method, invokeArgs) fci.size = sizeof(fci); fci.function_table = NULL; - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = object; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = object ? Z_OBJ_P(object) : NULL; + fci.retval = &retval; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -3071,28 +3343,30 @@ ZEND_METHOD(reflection_method, invokeArgs) fcc.function_handler = mptr; fcc.calling_scope = obj_ce; fcc.called_scope = intern->ce; - fcc.object_ptr = object; - - /* + fcc.object = (object) ? Z_OBJ_P(object) : NULL; + + /* * Copy the zend_function when calling via handler (e.g. Closure::__invoke()) */ - if (mptr->type == ZEND_INTERNAL_FUNCTION && - (mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0) { - fcc.function_handler = _copy_function(mptr TSRMLS_CC); + if ((mptr->internal_function.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) { + fcc.function_handler = _copy_function(mptr); } - result = zend_call_function(&fci, &fcc TSRMLS_CC); + result = zend_call_function(&fci, &fcc); + for (i = 0; i < argc; i++) { + zval_ptr_dtor(¶ms[i]); + } efree(params); if (result == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Invocation of method %s::%s() failed", mptr->common.scope->name, mptr->common.function_name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Invocation of method %s::%s() failed", ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); return; } - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + if (Z_TYPE(retval) != IS_UNDEF) { + ZVAL_COPY_VALUE(return_value, &retval); } } /* }}} */ @@ -3173,18 +3447,18 @@ ZEND_METHOD(reflection_function, isVariadic) Returns whether this function is defined in namespace */ ZEND_METHOD(reflection_function, inNamespace) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; } @@ -3196,20 +3470,20 @@ ZEND_METHOD(reflection_function, inNamespace) Returns the name of namespace where this function is defined */ ZEND_METHOD(reflection_function, getNamespaceName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(Z_STRVAL_PP(name), backslash - Z_STRVAL_PP(name), 1); + RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); } RETURN_EMPTY_STRING(); } @@ -3219,22 +3493,61 @@ ZEND_METHOD(reflection_function, getNamespaceName) Returns the short name of the function (without namespace part) */ ZEND_METHOD(reflection_function, getShortName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRLEN_PP(name) - (backslash - Z_STRVAL_PP(name) + 1), 1); + RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); + } + ZVAL_DEREF(name); + ZVAL_COPY(return_value, name); +} +/* }}} */ + +/* {{{ proto public bool ReflectionFunctionAbstract:hasReturnType() + Return whether the function has a return type */ +ZEND_METHOD(reflection_function, hasReturnType) +{ + reflection_object *intern; + zend_function *fptr; + + if (zend_parse_parameters_none() == FAILURE) { + return; } - RETURN_ZVAL(*name, 1, 0); + + GET_REFLECTION_OBJECT_PTR(fptr); + + RETVAL_BOOL(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE); +} +/* }}} */ + +/* {{{ proto public string ReflectionFunctionAbstract::getReturnType() + Returns the return type associated with the function */ +ZEND_METHOD(reflection_function, getReturnType) +{ + reflection_object *intern; + zend_function *fptr; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + GET_REFLECTION_OBJECT_PTR(fptr); + + if (!(fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) { + RETURN_NULL(); + } + + reflection_type_factory(_copy_function(fptr), Z_ISUNDEF(intern->obj)? NULL : &intern->obj, &fptr->common.arg_info[-1], return_value); } /* }}} */ @@ -3301,7 +3614,7 @@ ZEND_METHOD(reflection_method, getDeclaringClass) return; } - zend_reflection_class_factory(mptr->common.scope, return_value TSRMLS_CC); + zend_reflection_class_factory(mptr->common.scope, return_value); } /* }}} */ @@ -3320,12 +3633,12 @@ ZEND_METHOD(reflection_method, getPrototype) } if (!mptr->common.prototype) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Method %s::%s does not have a prototype", intern->ce->name, mptr->common.function_name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Method %s::%s does not have a prototype", ZSTR_VAL(intern->ce->name), ZSTR_VAL(mptr->common.function_name)); return; } - reflection_method_factory(mptr->common.prototype->common.scope, mptr->common.prototype, NULL, return_value TSRMLS_CC); + reflection_method_factory(mptr->common.prototype->common.scope, mptr->common.prototype, NULL, return_value); } /* }}} */ @@ -3336,15 +3649,11 @@ ZEND_METHOD(reflection_method, setAccessible) reflection_object *intern; zend_bool visible; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &visible) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &visible) == FAILURE) { return; } - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(getThis()); intern->ignore_visibility = visible; } @@ -3363,49 +3672,44 @@ static void reflection_class_object_ctor(INTERNAL_FUNCTION_PARAMETERS, int is_ob { zval *argument; zval *object; - zval *classname; + zval classname; reflection_object *intern; - zend_class_entry **ce; + zend_class_entry *ce; if (is_object) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &argument) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &argument) == FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &argument) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &argument) == FAILURE) { return; } } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); if (Z_TYPE_P(argument) == IS_OBJECT) { - MAKE_STD_ZVAL(classname); - ZVAL_STRINGL(classname, Z_OBJCE_P(argument)->name, Z_OBJCE_P(argument)->name_length, 1); - reflection_update_property(object, "name", classname); + ZVAL_STR_COPY(&classname, Z_OBJCE_P(argument)->name); + reflection_update_property(object, "name", &classname); intern->ptr = Z_OBJCE_P(argument); if (is_object) { - intern->obj = argument; - zval_add_ref(&argument); + ZVAL_COPY_VALUE(&intern->obj, argument); + zval_add_ref(argument); } } else { - convert_to_string_ex(&argument); - if (zend_lookup_class(Z_STRVAL_P(argument), Z_STRLEN_P(argument), &ce TSRMLS_CC) == FAILURE) { + convert_to_string_ex(argument); + if ((ce = zend_lookup_class(Z_STR_P(argument))) == NULL) { if (!EG(exception)) { - zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", Z_STRVAL_P(argument)); + zend_throw_exception_ex(reflection_exception_ptr, -1, "Class %s does not exist", Z_STRVAL_P(argument)); } return; } - MAKE_STD_ZVAL(classname); - ZVAL_STRINGL(classname, (*ce)->name, (*ce)->name_length, 1); - reflection_update_property(object, "name", classname); + ZVAL_STR_COPY(&classname, ce->name); + reflection_update_property(object, "name", &classname); - intern->ptr = *ce; + intern->ptr = ce; } intern->ref_type = REF_TYPE_OTHER; } @@ -3420,19 +3724,13 @@ ZEND_METHOD(reflection_class, __construct) /* }}} */ /* {{{ add_class_vars */ -static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value TSRMLS_DC) +static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value) { - HashPosition pos; zend_property_info *prop_info; - zval *prop, *prop_copy; - char *key; - uint key_len; - ulong num_index; - - zend_hash_internal_pointer_reset_ex(&ce->properties_info, &pos); - while (zend_hash_get_current_data_ex(&ce->properties_info, (void **) &prop_info, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&ce->properties_info, &key, &key_len, &num_index, 0, &pos); - zend_hash_move_forward_ex(&ce->properties_info, &pos); + zval *prop, prop_copy; + zend_string *key; + + ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, key, prop_info) { if (((prop_info->flags & ZEND_ACC_SHADOW) && prop_info->ce != ce) || ((prop_info->flags & ZEND_ACC_PROTECTED) && @@ -3442,31 +3740,29 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value continue; } prop = NULL; - if (prop_info->offset >= 0) { - if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) { - prop = ce->default_static_members_table[prop_info->offset]; - } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) { - prop = ce->default_properties_table[prop_info->offset]; - } + if (statics && (prop_info->flags & ZEND_ACC_STATIC) != 0) { + prop = &ce->default_static_members_table[prop_info->offset]; + } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) { + prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)]; } if (!prop) { continue; } /* copy: enforce read only access */ - ALLOC_ZVAL(prop_copy); - *prop_copy = *prop; - zval_copy_ctor(prop_copy); - INIT_PZVAL(prop_copy); + ZVAL_DEREF(prop); + ZVAL_DUP(&prop_copy, prop); /* this is necessary to make it able to work with default array * properties, returned to user */ - if (IS_CONSTANT_TYPE(Z_TYPE_P(prop_copy))) { - zval_update_constant(&prop_copy, 1 TSRMLS_CC); + if (Z_CONSTANT(prop_copy)) { + if (UNEXPECTED(zval_update_constant_ex(&prop_copy, 1, NULL) != SUCCESS)) { + return; + } } - add_assoc_zval(return_value, key, prop_copy); - } + zend_hash_update(Z_ARRVAL_P(return_value), key, &prop_copy); + } ZEND_HASH_FOREACH_END(); } /* }}} */ @@ -3483,10 +3779,12 @@ ZEND_METHOD(reflection_class, getStaticProperties) GET_REFLECTION_OBJECT_PTR(ce); - zend_update_class_constants(ce TSRMLS_CC); + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + return; + } array_init(return_value); - add_class_vars(ce, 1, return_value TSRMLS_CC); + add_class_vars(ce, 1, return_value); } /* }}} */ @@ -3496,65 +3794,61 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue) { reflection_object *intern; zend_class_entry *ce; - char *name; - int name_len; - zval **prop, *def_value = NULL; + zend_string *name; + zval *prop, *def_value = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &name, &name_len, &def_value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &name, &def_value) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - zend_update_class_constants(ce TSRMLS_CC); - prop = zend_std_get_static_property(ce, name, name_len, 1, NULL TSRMLS_CC); + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + return; + } + prop = zend_std_get_static_property(ce, name, 1); if (!prop) { if (def_value) { - RETURN_ZVAL(def_value, 1, 0); + ZVAL_COPY(return_value, def_value); } else { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not have a property named %s", ce->name, name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Class %s does not have a property named %s", ZSTR_VAL(ce->name), ZSTR_VAL(name)); } return; } else { - RETURN_ZVAL(*prop, 1, 0); + ZVAL_DEREF(prop); + ZVAL_COPY(return_value, prop); } } /* }}} */ -/* {{{ proto public void ReflectionClass::setStaticPropertyValue($name, $value) +/* {{{ proto public void ReflectionClass::setStaticPropertyValue(string $name, mixed $value) Sets the value of a static property */ ZEND_METHOD(reflection_class, setStaticPropertyValue) { reflection_object *intern; zend_class_entry *ce; - char *name; - int name_len; - zval **variable_ptr, *value; - int refcount; - zend_uchar is_ref; + zend_string *name; + zval *variable_ptr, *value; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &name_len, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &name, &value) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - zend_update_class_constants(ce TSRMLS_CC); - variable_ptr = zend_std_get_static_property(ce, name, name_len, 1, NULL TSRMLS_CC); + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + return; + } + variable_ptr = zend_std_get_static_property(ce, name, 1); if (!variable_ptr) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Class %s does not have a property named %s", ce->name, name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Class %s does not have a property named %s", ZSTR_VAL(ce->name), ZSTR_VAL(name)); return; } - refcount = Z_REFCOUNT_PP(variable_ptr); - is_ref = Z_ISREF_PP(variable_ptr); - zval_dtor(*variable_ptr); - **variable_ptr = *value; - zval_copy_ctor(*variable_ptr); - Z_SET_REFCOUNT_PP(variable_ptr, refcount); - Z_SET_ISREF_TO_PP(variable_ptr, is_ref); - + ZVAL_DEREF(variable_ptr); + zval_ptr_dtor(variable_ptr); + ZVAL_COPY(variable_ptr, value); } /* }}} */ @@ -3570,9 +3864,11 @@ ZEND_METHOD(reflection_class, getDefaultProperties) } GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - zend_update_class_constants(ce TSRMLS_CC); - add_class_vars(ce, 1, return_value TSRMLS_CC); - add_class_vars(ce, 0, return_value TSRMLS_CC); + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + return; + } + add_class_vars(ce, 1, return_value); + add_class_vars(ce, 0, return_value); } /* }}} */ @@ -3589,8 +3885,8 @@ ZEND_METHOD(reflection_class, __toString) } GET_REFLECTION_OBJECT_PTR(ce); string_init(&str); - _class_string(&str, ce, intern->obj, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _class_string(&str, ce, &intern->obj, ""); + RETURN_NEW_STR(str.buf); } /* }}} */ @@ -3601,7 +3897,7 @@ ZEND_METHOD(reflection_class, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); } /* }}} */ @@ -3635,6 +3931,21 @@ ZEND_METHOD(reflection_class, isUserDefined) } /* }}} */ +/* {{{ proto public bool ReflectionClass::isAnonymous() + Returns whether this class is anonymous */ +ZEND_METHOD(reflection_class, isAnonymous) +{ + reflection_object *intern; + zend_class_entry *ce; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + GET_REFLECTION_OBJECT_PTR(ce); + RETURN_BOOL(ce->ce_flags & ZEND_ACC_ANON_CLASS); +} +/* }}} */ + /* {{{ proto public string ReflectionClass::getFileName() Returns the filename of the file this class was declared in */ ZEND_METHOD(reflection_class, getFileName) @@ -3647,7 +3958,7 @@ ZEND_METHOD(reflection_class, getFileName) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS) { - RETURN_STRING(ce->info.user.filename, 1); + RETURN_STR_COPY(ce->info.user.filename); } RETURN_FALSE; } @@ -3701,7 +4012,7 @@ ZEND_METHOD(reflection_class, getDocComment) } GET_REFLECTION_OBJECT_PTR(ce); if (ce->type == ZEND_USER_CLASS && ce->info.user.doc_comment) { - RETURN_STRINGL(ce->info.user.doc_comment, ce->info.user.doc_comment_len, 1); + RETURN_STR_COPY(ce->info.user.doc_comment); } RETURN_FALSE; } @@ -3720,7 +4031,7 @@ ZEND_METHOD(reflection_class, getConstructor) GET_REFLECTION_OBJECT_PTR(ce); if (ce->constructor) { - reflection_method_factory(ce, ce->constructor, NULL, return_value TSRMLS_CC); + reflection_method_factory(ce, ce->constructor, NULL, return_value); } else { RETURN_NULL(); } @@ -3734,10 +4045,10 @@ ZEND_METHOD(reflection_class, hasMethod) reflection_object *intern; zend_class_entry *ce; char *name, *lc_name; - int name_len; + size_t name_len; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { return; } @@ -3745,7 +4056,7 @@ ZEND_METHOD(reflection_class, hasMethod) lc_name = zend_str_tolower_dup(name, name_len); if ((ce == zend_ce_closure && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) - || zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) { + || zend_hash_str_exists(&ce->function_table, lc_name, name_len)) { efree(lc_name); RETURN_TRUE; } else { @@ -3764,37 +4075,37 @@ ZEND_METHOD(reflection_class, getMethod) zend_function *mptr; zval obj_tmp; char *name, *lc_name; - int name_len; + size_t name_len; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); lc_name = zend_str_tolower_dup(name, name_len); - if (ce == zend_ce_closure && intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + if (ce == zend_ce_closure && !Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (mptr = zend_get_closure_invoke_method(intern->obj TSRMLS_CC)) != NULL) + && (mptr = zend_get_closure_invoke_method(Z_OBJ(intern->obj))) != NULL) { /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself */ - reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); + reflection_method_factory(ce, mptr, NULL, return_value); efree(lc_name); - } else if (ce == zend_ce_closure && !intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + } else if (ce == zend_ce_closure && Z_ISUNDEF(intern->obj) && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) { + && 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 */ - reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); + reflection_method_factory(ce, mptr, NULL, return_value); zval_dtor(&obj_tmp); efree(lc_name); - } else if (zend_hash_find(&ce->function_table, lc_name, name_len + 1, (void**) &mptr) == SUCCESS) { - reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); + } else if ((mptr = zend_hash_str_find_ptr(&ce->function_table, lc_name, name_len)) != NULL) { + reflection_method_factory(ce, mptr, NULL, return_value); efree(lc_name); } else { efree(lc_name); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Method %s does not exist", name); return; } @@ -3802,38 +4113,37 @@ ZEND_METHOD(reflection_class, getMethod) /* }}} */ /* {{{ _addmethod */ -static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, long filter, zval *obj TSRMLS_DC) +static void _addmethod(zend_function *mptr, zend_class_entry *ce, zval *retval, zend_long filter, zval *obj) { - zval *method; - uint len = strlen(mptr->common.function_name); + zval method; + size_t len = ZSTR_LEN(mptr->common.function_name); zend_function *closure; - if (mptr->common.fn_flags & filter) { - ALLOC_ZVAL(method); if (ce == zend_ce_closure && obj && (len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) - && memcmp(mptr->common.function_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 - && (closure = zend_get_closure_invoke_method(obj TSRMLS_CC)) != NULL) + && 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) { mptr = closure; } /* don't assign closure_object since we only reflect the invoke handler method and not the closure definition itself, even if we have a closure */ - reflection_method_factory(ce, mptr, NULL, method TSRMLS_CC); - add_next_index_zval(retval, method); + reflection_method_factory(ce, mptr, NULL, &method); + add_next_index_zval(retval, &method); } } /* }}} */ /* {{{ _addmethod */ -static int _addmethod_va(zend_function *mptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _addmethod_va(zval *el, int num_args, va_list args, zend_hash_key *hash_key) { + zend_function *mptr = (zend_function*)Z_PTR_P(el); zend_class_entry *ce = *va_arg(args, zend_class_entry**); zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); zval *obj = va_arg(args, zval *); - _addmethod(mptr, ce, retval, filter, obj TSRMLS_CC); + _addmethod(mptr, ce, retval, filter, obj); return ZEND_HASH_APPLY_KEEP; } /* }}} */ @@ -3844,12 +4154,12 @@ ZEND_METHOD(reflection_class, getMethods) { reflection_object *intern; zend_class_entry *ce; - long filter = 0; + zend_long filter = 0; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); if (argc) { - if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { + if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) { return; } } else { @@ -3860,12 +4170,12 @@ ZEND_METHOD(reflection_class, getMethods) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - zend_hash_apply_with_arguments(&ce->function_table TSRMLS_CC, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj); - if (intern->obj && instanceof_function(ce, zend_ce_closure TSRMLS_CC)) { - zend_function *closure = zend_get_closure_invoke_method(intern->obj TSRMLS_CC); + zend_hash_apply_with_arguments(&ce->function_table, (apply_func_args_t) _addmethod_va, 4, &ce, return_value, filter, intern->obj); + if (Z_TYPE(intern->obj) != IS_UNDEF && instanceof_function(ce, zend_ce_closure)) { + zend_function *closure = zend_get_closure_invoke_method(Z_OBJ(intern->obj)); if (closure) { - _addmethod(closure, ce, return_value, filter, intern->obj TSRMLS_CC); - _free_function(closure TSRMLS_CC); + _addmethod(closure, ce, return_value, filter, &intern->obj); + _free_function(closure); } } } @@ -3878,26 +4188,24 @@ ZEND_METHOD(reflection_class, hasProperty) reflection_object *intern; zend_property_info *property_info; zend_class_entry *ce; - char *name; - int name_len; - zval *property; + zend_string *name; + zval property; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len+1, (void **) &property_info) == SUCCESS) { + if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) { if (property_info->flags & ZEND_ACC_SHADOW) { RETURN_FALSE; } RETURN_TRUE; } else { - if (intern->obj && Z_OBJ_HANDLER_P(intern->obj, has_property)) { - MAKE_STD_ZVAL(property); - ZVAL_STRINGL(property, name, name_len, 1); - if (Z_OBJ_HANDLER_P(intern->obj, has_property)(intern->obj, property, 2, 0 TSRMLS_CC)) { + if (Z_TYPE(intern->obj) != IS_UNDEF && Z_OBJ_HANDLER(intern->obj, has_property)) { + ZVAL_STR_COPY(&property, name); + if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, NULL)) { zval_ptr_dtor(&property); RETURN_TRUE; } @@ -3913,75 +4221,79 @@ ZEND_METHOD(reflection_class, hasProperty) ZEND_METHOD(reflection_class, getProperty) { reflection_object *intern; - zend_class_entry *ce, **pce; + zend_class_entry *ce, *ce2; zend_property_info *property_info; - char *name, *tmp, *classname; - int name_len, classname_len; + zend_string *name, *classname; + char *tmp, *str_name; + size_t classname_len, str_name_len; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS) { + 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 TSRMLS_CC); + reflection_property_factory(ce, property_info, return_value); return; } - } else if (intern->obj) { + } else if (Z_TYPE(intern->obj) != IS_UNDEF) { /* Check for dynamic properties */ - if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) { + 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 = estrndup(name, name_len); - property_info_tmp.name_length = name_len; - property_info_tmp.h = zend_get_hash_value(name, name_len+1); + property_info_tmp.name = zend_string_copy(name); property_info_tmp.doc_comment = NULL; property_info_tmp.ce = ce; - reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC); - intern = (reflection_object *) zend_object_store_get_object(return_value TSRMLS_CC); + reflection_property_factory(ce, &property_info_tmp, return_value); + intern = Z_REFLECTION_P(return_value); intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY; return; } } - if ((tmp = strstr(name, "::")) != NULL) { - classname_len = tmp - name; - classname = zend_str_tolower_dup(name, classname_len); - classname[classname_len] = '\0'; - name_len = name_len - (classname_len + 2); - name = tmp + 2; - - if (zend_lookup_class(classname, classname_len, &pce TSRMLS_CC) == FAILURE) { + 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); + zend_str_tolower_copy(ZSTR_VAL(classname), ZSTR_VAL(name), classname_len); + ZSTR_VAL(classname)[classname_len] = '\0'; + str_name_len = ZSTR_LEN(name) - (classname_len + 2); + str_name = tmp + 2; + + ce2 = zend_lookup_class(classname); + if (!ce2) { if (!EG(exception)) { - zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Class %s does not exist", classname); + zend_throw_exception_ex(reflection_exception_ptr, -1, "Class %s does not exist", ZSTR_VAL(classname)); } - efree(classname); + zend_string_release(classname); return; } - efree(classname); + zend_string_release(classname); - if (!instanceof_function(ce, *pce TSRMLS_CC)) { - zend_throw_exception_ex(reflection_exception_ptr, -1 TSRMLS_CC, "Fully qualified property name %s::%s does not specify a base class of %s", (*pce)->name, name, ce->name); + 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)); return; } - ce = *pce; + ce = ce2; - if (zend_hash_find(&ce->properties_info, name, name_len + 1, (void**) &property_info) == SUCCESS && (property_info->flags & ZEND_ACC_SHADOW) == 0) { - reflection_property_factory(ce, property_info, return_value TSRMLS_CC); + 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); return; } } - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Property %s does not exist", name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Property %s does not exist", str_name); } /* }}} */ /* {{{ _addproperty */ -static int _addproperty(zend_property_info *pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _addproperty(zval *el, int num_args, va_list args, zend_hash_key *hash_key) { - zval *property; + zval property; + zend_property_info *pptr = (zend_property_info*)Z_PTR_P(el); zend_class_entry *ce = *va_arg(args, zend_class_entry**); zval *retval = va_arg(args, zval*); long filter = va_arg(args, long); @@ -3991,38 +4303,41 @@ static int _addproperty(zend_property_info *pptr TSRMLS_DC, int num_args, va_lis } if (pptr->flags & filter) { - ALLOC_ZVAL(property); - reflection_property_factory(ce, pptr, property TSRMLS_CC); - add_next_index_zval(retval, property); + reflection_property_factory(ce, pptr, &property); + add_next_index_zval(retval, &property); } return 0; } /* }}} */ /* {{{ _adddynproperty */ -static int _adddynproperty(zval **pptr TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _adddynproperty(zval *ptr, int num_args, va_list args, zend_hash_key *hash_key) { - zval *property; + zval property; zend_class_entry *ce = *va_arg(args, zend_class_entry**); - zval *retval = va_arg(args, zval*), member; + zval *retval = va_arg(args, zval*); /* under some circumstances, the properties hash table may contain numeric * properties (e.g. when casting from array). This is a WONT FIX bug, at * least for the moment. Ignore these */ - if (hash_key->nKeyLength == 0) { + if (hash_key->key == NULL) { return 0; } - if (hash_key->arKey[0] == '\0') { + if (ZSTR_VAL(hash_key->key)[0] == '\0') { return 0; /* non public cannot be dynamic */ } - ZVAL_STRINGL(&member, hash_key->arKey, hash_key->nKeyLength-1, 0); - if (zend_get_property_info(ce, &member, 1 TSRMLS_CC) == &EG(std_property_info)) { - MAKE_STD_ZVAL(property); - EG(std_property_info).flags = ZEND_ACC_IMPLICIT_PUBLIC; - reflection_property_factory(ce, &EG(std_property_info), property TSRMLS_CC); - add_next_index_zval(retval, property); + if (zend_get_property_info(ce, hash_key->key, 1) == NULL) { + zend_property_info property_info; + + property_info.doc_comment = NULL; + property_info.flags = ZEND_ACC_IMPLICIT_PUBLIC; + property_info.name = hash_key->key; + property_info.ce = ce; + property_info.offset = -1; + reflection_property_factory(ce, &property_info, &property); + add_next_index_zval(retval, &property); } return 0; } @@ -4034,12 +4349,12 @@ ZEND_METHOD(reflection_class, getProperties) { reflection_object *intern; zend_class_entry *ce; - long filter = 0; + zend_long filter = 0; int argc = ZEND_NUM_ARGS(); METHOD_NOTSTATIC(reflection_class_ptr); if (argc) { - if (zend_parse_parameters(argc TSRMLS_CC, "|l", &filter) == FAILURE) { + if (zend_parse_parameters(argc, "|l", &filter) == FAILURE) { return; } } else { @@ -4050,11 +4365,11 @@ ZEND_METHOD(reflection_class, getProperties) GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - zend_hash_apply_with_arguments(&ce->properties_info TSRMLS_CC, (apply_func_args_t) _addproperty, 3, &ce, return_value, filter); + zend_hash_apply_with_arguments(&ce->properties_info, (apply_func_args_t) _addproperty, 3, &ce, return_value, filter); - if (intern->obj && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT_P(intern->obj)->get_properties) { - HashTable *properties = Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC); - zend_hash_apply_with_arguments(properties TSRMLS_CC, (apply_func_args_t) _adddynproperty, 2, &ce, return_value); + if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT(intern->obj)->get_properties) { + HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(&intern->obj); + zend_hash_apply_with_arguments(properties, (apply_func_args_t) _adddynproperty, 2, &ce, return_value); } } /* }}} */ @@ -4065,16 +4380,15 @@ ZEND_METHOD(reflection_class, hasConstant) { reflection_object *intern; zend_class_entry *ce; - char *name; - int name_len; + zend_string *name; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - if (zend_hash_exists(&ce->constants_table, name, name_len + 1)) { + if (zend_hash_exists(&ce->constants_table, name)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -4086,17 +4400,22 @@ ZEND_METHOD(reflection_class, hasConstant) Returns an associative array containing this class' constants and their values */ ZEND_METHOD(reflection_class, getConstants) { - zval *tmp_copy; reflection_object *intern; zend_class_entry *ce; + zval *val; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); array_init(return_value); - zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC); - zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); + ZEND_HASH_FOREACH_VAL(&ce->constants_table, val) { + ZVAL_DEREF(val); + if (UNEXPECTED(zval_update_constant_ex(val, 1, ce) != SUCCESS)) { + return; + } + } ZEND_HASH_FOREACH_END(); + zend_hash_copy(Z_ARRVAL_P(return_value), &ce->constants_table, zval_add_ref_unref); } /* }}} */ @@ -4106,21 +4425,25 @@ ZEND_METHOD(reflection_class, getConstant) { reflection_object *intern; zend_class_entry *ce; - zval **value; - char *name; - int name_len; + zval *value; + zend_string *name; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - zend_hash_apply_with_argument(&ce->constants_table, (apply_func_arg_t)zval_update_constant_inline_change, ce TSRMLS_CC); - if (zend_hash_find(&ce->constants_table, name, name_len + 1, (void **) &value) == FAILURE) { + ZEND_HASH_FOREACH_VAL(&ce->constants_table, value) { + ZVAL_DEREF(value); + if (UNEXPECTED(zval_update_constant_ex(value, 1, ce) != SUCCESS)) { + return; + } + } ZEND_HASH_FOREACH_END(); + if ((value = zend_hash_find(&ce->constants_table, name)) == NULL) { RETURN_FALSE; } - MAKE_COPY_ZVAL(value, return_value); + ZVAL_DUP(return_value, value); } /* }}} */ @@ -4149,7 +4472,7 @@ ZEND_METHOD(reflection_class, isInstantiable) return; } GET_REFLECTION_OBJECT_PTR(ce); - if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) { + if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) { RETURN_FALSE; } @@ -4178,17 +4501,19 @@ ZEND_METHOD(reflection_class, isCloneable) if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS)) { RETURN_FALSE; } - if (intern->obj) { + if (!Z_ISUNDEF(intern->obj)) { if (ce->clone) { RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); } else { - RETURN_BOOL(Z_OBJ_HANDLER_P(intern->obj, clone_obj) != NULL); + RETURN_BOOL(Z_OBJ_HANDLER(intern->obj, clone_obj) != NULL); } } else { if (ce->clone) { RETURN_BOOL(ce->clone->common.fn_flags & ZEND_ACC_PUBLIC); } else { - object_init_ex(&obj, ce); + if (UNEXPECTED(object_init_ex(&obj, ce) != SUCCESS)) { + return; + } RETVAL_BOOL(Z_OBJ_HANDLER(obj, clone_obj) != NULL); zval_dtor(&obj); } @@ -4208,7 +4533,7 @@ ZEND_METHOD(reflection_class, isInterface) Returns whether this is a trait */ ZEND_METHOD(reflection_class, isTrait) { - _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT & ~ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_TRAIT); } /* }}} */ @@ -4216,7 +4541,7 @@ ZEND_METHOD(reflection_class, isTrait) Returns whether this class is final */ ZEND_METHOD(reflection_class, isFinal) { - _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL_CLASS); + _class_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_FINAL); } /* }}} */ @@ -4240,7 +4565,7 @@ ZEND_METHOD(reflection_class, getModifiers) } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_LONG(ce->ce_flags); + RETURN_LONG(ce->ce_flags & ~(ZEND_ACC_CONSTANTS_UPDATED|ZEND_ACC_USE_GUARDS)); } /* }}} */ @@ -4253,11 +4578,11 @@ ZEND_METHOD(reflection_class, isInstance) zval *object; METHOD_NOTSTATIC(reflection_class_ptr); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &object) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &object) == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ce); - RETURN_BOOL(HAS_CLASS_ENTRY(*object) && instanceof_function(Z_OBJCE_P(object), ce TSRMLS_CC)); + RETURN_BOOL(instanceof_function(Z_OBJCE_P(object), ce)); } /* }}} */ @@ -4265,7 +4590,7 @@ ZEND_METHOD(reflection_class, isInstance) Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstance) { - zval *retval_ptr = NULL; + zval retval; reflection_object *intern; zend_class_entry *ce, *old_scope; zend_function *constructor; @@ -4273,40 +4598,43 @@ ZEND_METHOD(reflection_class, newInstance) METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); - object_init_ex(return_value, ce); + if (UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) { + return; + } old_scope = EG(scope); EG(scope) = ce; - constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC); + constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value)); EG(scope) = old_scope; /* Run the constructor if there is one */ if (constructor) { - zval ***params = NULL; - int num_args = 0; + zval *params = NULL; + int ret, i, num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %s", ZSTR_VAL(ce->name)); zval_dtor(return_value); RETURN_NULL(); } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) { - if (params) { - efree(params); - } + if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", ¶ms, &num_args) == FAILURE) { zval_dtor(return_value); RETURN_FALSE; } + for (i = 0; i < num_args; i++) { + if (Z_REFCOUNTED(params[i])) Z_ADDREF(params[i]); + } + fci.size = sizeof(fci); fci.function_table = EG(function_table); - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = return_value; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = Z_OBJ_P(return_value); + fci.retval = &retval; fci.param_count = num_args; fci.params = params; fci.no_separation = 1; @@ -4315,27 +4643,20 @@ ZEND_METHOD(reflection_class, newInstance) fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - fcc.object_ptr = return_value; + fcc.object = Z_OBJ_P(return_value); - if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - if (params) { - efree(params); - } - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name); + ret = zend_call_function(&fci, &fcc); + zval_ptr_dtor(&retval); + for (i = 0; i < num_args; i++) { + zval_ptr_dtor(¶ms[i]); + } + if (ret == FAILURE) { + php_error_docref(NULL, E_WARNING, "Invocation of %s's constructor failed", ZSTR_VAL(ce->name)); zval_dtor(return_value); RETURN_NULL(); } - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } - if (params) { - efree(params); - } } else if (ZEND_NUM_ARGS()) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ZSTR_VAL(ce->name)); } } /* }}} */ @@ -4350,8 +4671,9 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); - if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL_CLASS) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s is an internal class marked as final that cannot be instantiated without invoking its constructor", ce->name); + if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s is an internal class marked as final that cannot be instantiated without invoking its constructor", ZSTR_VAL(ce->name)); + return; } object_init_ex(return_value, ce); @@ -4362,10 +4684,10 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor) Returns an instance of this class */ ZEND_METHOD(reflection_class, newInstanceArgs) { - zval *retval_ptr = NULL; + zval retval, *val; reflection_object *intern; zend_class_entry *ce, *old_scope; - int argc = 0; + int ret, i, argc = 0; HashTable *args; zend_function *constructor; @@ -4373,7 +4695,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &args) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|h", &args) == FAILURE) { return; } @@ -4381,37 +4703,42 @@ ZEND_METHOD(reflection_class, newInstanceArgs) argc = args->nNumOfElements; } - object_init_ex(return_value, ce); + if (UNEXPECTED(object_init_ex(return_value, ce) != SUCCESS)) { + return; + } old_scope = EG(scope); EG(scope) = ce; - constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC); + constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value)); EG(scope) = old_scope; /* Run the constructor if there is one */ if (constructor) { - zval ***params = NULL; + zval *params = NULL; zend_fcall_info fci; zend_fcall_info_cache fcc; if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Access to non-public constructor of class %s", ZSTR_VAL(ce->name)); zval_dtor(return_value); RETURN_NULL(); } if (argc) { - params = safe_emalloc(sizeof(zval **), argc, 0); - zend_hash_apply_with_argument(args, (apply_func_arg_t)_zval_array_to_c_array, ¶ms TSRMLS_CC); - params -= argc; + params = safe_emalloc(sizeof(zval), argc, 0); + argc = 0; + ZEND_HASH_FOREACH_VAL(args, val) { + ZVAL_COPY(¶ms[argc], val); + argc++; + } ZEND_HASH_FOREACH_END(); } fci.size = sizeof(fci); fci.function_table = EG(function_table); - fci.function_name = NULL; + ZVAL_UNDEF(&fci.function_name); fci.symbol_table = NULL; - fci.object_ptr = return_value; - fci.retval_ptr_ptr = &retval_ptr; + fci.object = Z_OBJ_P(return_value); + fci.retval = &retval; fci.param_count = argc; fci.params = params; fci.no_separation = 1; @@ -4420,27 +4747,24 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); - fcc.object_ptr = return_value; + fcc.object = Z_OBJ_P(return_value); - if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { - if (params) { - efree(params); - } - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); + ret = zend_call_function(&fci, &fcc); + zval_ptr_dtor(&retval); + if (params) { + for (i = 0; i < argc; i++) { + zval_ptr_dtor(¶ms[i]); } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name); + efree(params); + } + 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); RETURN_NULL(); } - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } - if (params) { - efree(params); - } } else if (argc) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ZSTR_VAL(ce->name)); } } /* }}} */ @@ -4461,13 +4785,12 @@ ZEND_METHOD(reflection_class, getInterfaces) array_init(return_value); if (ce->num_interfaces) { - zend_uint i; + uint32_t i; for (i=0; i < ce->num_interfaces; i++) { - zval *interface; - ALLOC_ZVAL(interface); - zend_reflection_class_factory(ce->interfaces[i], interface TSRMLS_CC); - add_assoc_zval_ex(return_value, ce->interfaces[i]->name, ce->interfaces[i]->name_length + 1, interface); + zval interface; + zend_reflection_class_factory(ce->interfaces[i], &interface); + zend_hash_update(Z_ARRVAL_P(return_value), ce->interfaces[i]->name, &interface); } } } @@ -4479,7 +4802,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames) { reflection_object *intern; zend_class_entry *ce; - zend_uint i; + uint32_t i; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4490,7 +4813,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames) array_init(return_value); for (i=0; i < ce->num_interfaces; i++) { - add_next_index_stringl(return_value, ce->interfaces[i]->name, ce->interfaces[i]->name_length, 1); + add_next_index_str(return_value, zend_string_copy(ce->interfaces[i]->name)); } } /* }}} */ @@ -4501,7 +4824,7 @@ ZEND_METHOD(reflection_class, getTraits) { reflection_object *intern; zend_class_entry *ce; - zend_uint i; + uint32_t i; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4511,10 +4834,9 @@ ZEND_METHOD(reflection_class, getTraits) array_init(return_value); for (i=0; i < ce->num_traits; i++) { - zval *trait; - ALLOC_ZVAL(trait); - zend_reflection_class_factory(ce->traits[i], trait TSRMLS_CC); - add_assoc_zval_ex(return_value, ce->traits[i]->name, ce->traits[i]->name_length + 1, trait); + zval trait; + zend_reflection_class_factory(ce->traits[i], &trait); + zend_hash_update(Z_ARRVAL_P(return_value), ce->traits[i]->name, &trait); } } /* }}} */ @@ -4525,7 +4847,7 @@ ZEND_METHOD(reflection_class, getTraitNames) { reflection_object *intern; zend_class_entry *ce; - zend_uint i; + uint32_t i; if (zend_parse_parameters_none() == FAILURE) { return; @@ -4535,7 +4857,7 @@ ZEND_METHOD(reflection_class, getTraitNames) array_init(return_value); for (i=0; i < ce->num_traits; i++) { - add_next_index_stringl(return_value, ce->traits[i]->name, ce->traits[i]->name_length, 1); + add_next_index_str(return_value, zend_string_copy(ce->traits[i]->name)); } } /* }}} */ @@ -4555,15 +4877,16 @@ ZEND_METHOD(reflection_class, getTraitAliases) array_init(return_value); if (ce->trait_aliases) { - zend_uint i = 0; + uint32_t i = 0; while (ce->trait_aliases[i]) { - char *method_name; - int method_name_len; + zend_string *mname; zend_trait_method_reference *cur_ref = ce->trait_aliases[i]->trait_method; if (ce->trait_aliases[i]->alias) { - method_name_len = spprintf(&method_name, 0, "%s::%s", cur_ref->ce->name, cur_ref->method_name); - add_assoc_stringl_ex(return_value, ce->trait_aliases[i]->alias, ce->trait_aliases[i]->alias_len + 1, method_name, method_name_len, 0); + + 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)); + add_assoc_str_ex(return_value, ZSTR_VAL(ce->trait_aliases[i]->alias), ZSTR_LEN(ce->trait_aliases[i]->alias), mname); } i++; } @@ -4584,7 +4907,7 @@ ZEND_METHOD(reflection_class, getParentClass) GET_REFLECTION_OBJECT_PTR(ce); if (ce->parent) { - zend_reflection_class_factory(ce->parent, return_value TSRMLS_CC); + zend_reflection_class_factory(ce->parent, return_value); } else { RETURN_FALSE; } @@ -4596,30 +4919,29 @@ ZEND_METHOD(reflection_class, getParentClass) ZEND_METHOD(reflection_class, isSubclassOf) { reflection_object *intern, *argument; - zend_class_entry *ce, **pce, *class_ce; + 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() TSRMLS_CC, "z", &class_name) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &class_name) == FAILURE) { return; } - switch(class_name->type) { + switch (Z_TYPE_P(class_name)) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(class_name), Z_STRLEN_P(class_name), &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + if ((class_ce = zend_lookup_class(Z_STR_P(class_name))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not exist", Z_STRVAL_P(class_name)); return; } - class_ce = *pce; break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr TSRMLS_CC)) { - argument = (reflection_object *) zend_object_store_get_object(class_name TSRMLS_CC); + if (instanceof_function(Z_OBJCE_P(class_name), reflection_class_ptr)) { + argument = Z_REFLECTION_P(class_name); if (argument == NULL || argument->ptr == NULL) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); + php_error_docref(NULL, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); /* Bails out */ } class_ce = argument->ptr; @@ -4627,12 +4949,12 @@ ZEND_METHOD(reflection_class, isSubclassOf) } /* no break */ default: - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Parameter one must either be a string or a ReflectionClass object"); return; } - RETURN_BOOL((ce != class_ce && instanceof_function(ce, class_ce TSRMLS_CC))); + RETURN_BOOL((ce != class_ce && instanceof_function(ce, class_ce))); } /* }}} */ @@ -4641,30 +4963,29 @@ ZEND_METHOD(reflection_class, isSubclassOf) ZEND_METHOD(reflection_class, implementsInterface) { reflection_object *intern, *argument; - zend_class_entry *ce, *interface_ce, **pce; + 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() TSRMLS_CC, "z", &interface) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &interface) == FAILURE) { return; } - switch(interface->type) { + switch (Z_TYPE_P(interface)) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(interface), Z_STRLEN_P(interface), &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + if ((interface_ce = zend_lookup_class(Z_STR_P(interface))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Interface %s does not exist", Z_STRVAL_P(interface)); return; } - interface_ce = *pce; break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr TSRMLS_CC)) { - argument = (reflection_object *) zend_object_store_get_object(interface TSRMLS_CC); + if (instanceof_function(Z_OBJCE_P(interface), reflection_class_ptr)) { + argument = Z_REFLECTION_P(interface); if (argument == NULL || argument->ptr == NULL) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); + php_error_docref(NULL, E_ERROR, "Internal error: Failed to retrieve the argument's reflection object"); /* Bails out */ } interface_ce = argument->ptr; @@ -4672,17 +4993,17 @@ ZEND_METHOD(reflection_class, implementsInterface) } /* no break */ default: - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Parameter one must either be a string or a ReflectionClass object"); return; } if (!(interface_ce->ce_flags & ZEND_ACC_INTERFACE)) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Interface %s is a Class", interface_ce->name); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Interface %s is a Class", ZSTR_VAL(interface_ce->name)); return; } - RETURN_BOOL(instanceof_function(ce, interface_ce TSRMLS_CC)); + RETURN_BOOL(instanceof_function(ce, interface_ce)); } /* }}} */ @@ -4719,7 +5040,7 @@ ZEND_METHOD(reflection_class, getExtension) GET_REFLECTION_OBJECT_PTR(ce); if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) { - reflection_extension_factory(return_value, ce->info.internal.module->name TSRMLS_CC); + reflection_extension_factory(return_value, ce->info.internal.module->name); } } /* }}} */ @@ -4739,7 +5060,7 @@ ZEND_METHOD(reflection_class, getExtensionName) GET_REFLECTION_OBJECT_PTR(ce); if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module) { - RETURN_STRING(ce->info.internal.module->name, 1); + RETURN_STRING(ce->info.internal.module->name); } else { RETURN_FALSE; } @@ -4750,18 +5071,18 @@ ZEND_METHOD(reflection_class, getExtensionName) Returns whether this class is defined in namespace */ ZEND_METHOD(reflection_class, inNamespace) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { RETURN_TRUE; } @@ -4773,20 +5094,20 @@ ZEND_METHOD(reflection_class, inNamespace) Returns the name of namespace where this class is defined */ ZEND_METHOD(reflection_class, getNamespaceName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(Z_STRVAL_PP(name), backslash - Z_STRVAL_PP(name), 1); + RETURN_STRINGL(Z_STRVAL_P(name), backslash - Z_STRVAL_P(name)); } RETURN_EMPTY_STRING(); } @@ -4796,22 +5117,23 @@ ZEND_METHOD(reflection_class, getNamespaceName) Returns the short name of the class (without namespace part) */ ZEND_METHOD(reflection_class, getShortName) { - zval **name; + zval *name; const char *backslash; if (zend_parse_parameters_none() == FAILURE) { return; } - if (zend_hash_find(Z_OBJPROP_P(getThis()), "name", sizeof("name"), (void **) &name) == FAILURE) { + if ((name = _default_load_entry(getThis(), "name", sizeof("name")-1)) == NULL) { RETURN_FALSE; } - if (Z_TYPE_PP(name) == IS_STRING - && (backslash = zend_memrchr(Z_STRVAL_PP(name), '\\', Z_STRLEN_PP(name))) - && backslash > Z_STRVAL_PP(name)) + if (Z_TYPE_P(name) == IS_STRING + && (backslash = zend_memrchr(Z_STRVAL_P(name), '\\', Z_STRLEN_P(name))) + && backslash > Z_STRVAL_P(name)) { - RETURN_STRINGL(backslash + 1, Z_STRLEN_PP(name) - (backslash - Z_STRVAL_PP(name) + 1), 1); + RETURN_STRINGL(backslash + 1, Z_STRLEN_P(name) - (backslash - Z_STRVAL_P(name) + 1)); } - RETURN_ZVAL(*name, 1, 0); + ZVAL_DEREF(name); + ZVAL_COPY(return_value, name); } /* }}} */ @@ -4843,36 +5165,31 @@ ZEND_METHOD(reflection_property, export) Constructor. Throws an Exception in case the given property does not exist */ ZEND_METHOD(reflection_property, __construct) { - zval *propname, *classname; + zval propname, cname, *classname; char *name_str; - const char *class_name, *prop_name; - int name_len, dynam_prop = 0; + size_t name_len; + int dynam_prop = 0; zval *object; reflection_object *intern; - zend_class_entry **pce; zend_class_entry *ce; zend_property_info *property_info = NULL; property_reference *reference; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &classname, &name_str, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { return; } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); /* Find the class entry */ switch (Z_TYPE_P(classname)) { case IS_STRING: - if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + if ((ce = zend_lookup_class(Z_STR_P(classname))) == NULL) { + zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s does not exist", Z_STRVAL_P(classname)); return; } - ce = *pce; break; case IS_OBJECT: @@ -4884,15 +5201,15 @@ ZEND_METHOD(reflection_property, __construct) /* returns out of this function */ } - if (zend_hash_find(&ce->properties_info, name_str, name_len + 1, (void **) &property_info) == FAILURE || (property_info->flags & ZEND_ACC_SHADOW)) { + if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, name_str, name_len)) == 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_exists(Z_OBJ_HT_P(classname)->get_properties(classname TSRMLS_CC), name_str, name_len+1)) { + if (zend_hash_str_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name_str, name_len)) { dynam_prop = 1; } } if (dynam_prop == 0) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Property %s::$%s does not exist", ce->name, name_str); + zend_throw_exception_ex(reflection_exception_ptr, 0, "Property %s::$%s does not exist", ZSTR_VAL(ce->name), name_str); return; } } @@ -4902,33 +5219,30 @@ ZEND_METHOD(reflection_property, __construct) zend_class_entry *tmp_ce = ce; zend_property_info *tmp_info; - while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, name_str, name_len + 1, (void **) &tmp_info) != SUCCESS) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, name_str, name_len)) == NULL) { ce = tmp_ce; property_info = tmp_info; tmp_ce = tmp_ce->parent; } } - MAKE_STD_ZVAL(classname); - MAKE_STD_ZVAL(propname); - if (dynam_prop == 0) { - zend_unmangle_property_name(property_info->name, property_info->name_length, &class_name, &prop_name); - ZVAL_STRINGL(classname, property_info->ce->name, property_info->ce->name_length, 1); - ZVAL_STRING(propname, prop_name, 1); + 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_STRINGL(classname, ce->name, ce->name_length, 1); - ZVAL_STRINGL(propname, name_str, name_len, 1); + ZVAL_STR_COPY(&cname, ce->name); + ZVAL_STRINGL(&propname, name_str, name_len); } - reflection_update_property(object, "class", classname); - reflection_update_property(object, "name", propname); + reflection_update_property(object, "class", &cname); + reflection_update_property(object, "name", &propname); reference = (property_reference*) emalloc(sizeof(property_reference)); if (dynam_prop) { reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC; - reference->prop.name = Z_STRVAL_P(propname); - reference->prop.name_length = Z_STRLEN_P(propname); - reference->prop.h = zend_get_hash_value(name_str, name_len+1); + reference->prop.name = Z_STR(propname); reference->prop.doc_comment = NULL; reference->prop.ce = ce; } else { @@ -4955,8 +5269,8 @@ ZEND_METHOD(reflection_property, __toString) } GET_REFLECTION_OBJECT_PTR(ref); string_init(&str); - _property_string(&str, &ref->prop, NULL, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _property_string(&str, &ref->prop, NULL, ""); + RETURN_NEW_STR(str.buf); } /* }}} */ @@ -4967,7 +5281,7 @@ ZEND_METHOD(reflection_property, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); } /* }}} */ @@ -5046,41 +5360,43 @@ ZEND_METHOD(reflection_property, getValue) { reflection_object *intern; property_reference *ref; - zval *object, name; + 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) { - _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); - zval_dtor(&name); + name = _default_load_entry(getThis(), "name", sizeof("name")-1); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Cannot access non-public member %s::%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name)); return; } if ((ref->prop.flags & ZEND_ACC_STATIC)) { - zend_update_class_constants(intern->ce TSRMLS_CC); - if (!CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name); + if (UNEXPECTED(zend_update_class_constants(intern->ce) != SUCCESS)) { + return; + } + if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) { + php_error_docref(NULL, E_ERROR, "Internal error: Could not find the property %s::%s", ZSTR_VAL(intern->ce->name), ZSTR_VAL(ref->prop.name)); /* Bails out */ } - *return_value= *CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]; - zval_copy_ctor(return_value); - INIT_PZVAL(return_value); + ZVAL_DUP(return_value, &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]); } else { const char *class_name, *prop_name; + size_t prop_name_len; + zval rv; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &object) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &object) == FAILURE) { return; } - zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name); - member_p = zend_read_property(ref->ce, object, prop_name, strlen(prop_name), 1 TSRMLS_CC); - MAKE_COPY_ZVAL(&member_p, return_value); - if (member_p != EG(uninitialized_zval_ptr)) { - zval_add_ref(&member_p); - zval_ptr_dtor(&member_p); + + 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); + if (member_p != &rv) { + ZVAL_COPY(return_value, member_p); + } else { + ZVAL_COPY_VALUE(return_value, member_p); } } } @@ -5092,8 +5408,8 @@ ZEND_METHOD(reflection_property, setValue) { reflection_object *intern; property_reference *ref; - zval **variable_ptr; - zval *object, name; + zval *variable_ptr; + zval *object, *name; zval *value; zval *tmp; @@ -5101,57 +5417,49 @@ ZEND_METHOD(reflection_property, setValue) GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { - _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); - zval_dtor(&name); + name = _default_load_entry(getThis(), "name", sizeof("name")-1); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "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 (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &tmp, &value) == FAILURE) { + 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; } } - zend_update_class_constants(intern->ce TSRMLS_CC); + if (UNEXPECTED(zend_update_class_constants(intern->ce) != SUCCESS)) { + return; + } - if (!CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop.name); + if (Z_TYPE(CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]) == IS_UNDEF) { + php_error_docref(NULL, E_ERROR, "Internal error: Could not find the property %s::%s", ZSTR_VAL(intern->ce->name), ZSTR_VAL(ref->prop.name)); /* Bails out */ } variable_ptr = &CE_STATIC_MEMBERS(intern->ce)[ref->prop.offset]; - if (*variable_ptr != value) { - if (PZVAL_IS_REF(*variable_ptr)) { - zval garbage = **variable_ptr; /* old value should be destroyed */ - - /* To check: can't *variable_ptr be some system variable like error_zval here? */ - Z_TYPE_PP(variable_ptr) = Z_TYPE_P(value); - (*variable_ptr)->value = value->value; - if (Z_REFCOUNT_P(value) > 0) { - zval_copy_ctor(*variable_ptr); - } - zval_dtor(&garbage); - } else { - zval *garbage = *variable_ptr; + if (variable_ptr != value) { + zval garbage; - /* if we assign referenced variable, we should separate it */ - Z_ADDREF_P(value); - if (PZVAL_IS_REF(value)) { - SEPARATE_ZVAL(&value); - } - *variable_ptr = value; - zval_ptr_dtor(&garbage); - } + ZVAL_DEREF(variable_ptr); + ZVAL_DEREF(value); + + ZVAL_COPY_VALUE(&garbage, variable_ptr); + + ZVAL_COPY(variable_ptr, value); + + zval_ptr_dtor(&garbage); } } else { const char *class_name, *prop_name; + size_t prop_name_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oz", &object, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "oz", &object, &value) == FAILURE) { return; } - zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name); - zend_update_property(ref->ce, object, prop_name, strlen(prop_name), value TSRMLS_CC); + + 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); } } /* }}} */ @@ -5165,20 +5473,19 @@ ZEND_METHOD(reflection_property, getDeclaringClass) zend_class_entry *tmp_ce, *ce; zend_property_info *tmp_info; const char *prop_name, *class_name; - int prop_name_len; + size_t prop_name_len; if (zend_parse_parameters_none() == FAILURE) { return; } GET_REFLECTION_OBJECT_PTR(ref); - if (zend_unmangle_property_name(ref->prop.name, ref->prop.name_length, &class_name, &prop_name) != SUCCESS) { + if (zend_unmangle_property_name_ex(ref->prop.name, &class_name, &prop_name, &prop_name_len) != SUCCESS) { RETURN_FALSE; } - prop_name_len = strlen(prop_name); ce = tmp_ce = ref->ce; - while (tmp_ce && zend_hash_find(&tmp_ce->properties_info, prop_name, prop_name_len + 1, (void **) &tmp_info) == SUCCESS) { + while (tmp_ce && (tmp_info = zend_hash_str_find_ptr(&tmp_ce->properties_info, prop_name, prop_name_len)) != 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; @@ -5191,7 +5498,7 @@ ZEND_METHOD(reflection_property, getDeclaringClass) tmp_ce = tmp_ce->parent; } - zend_reflection_class_factory(ce, return_value TSRMLS_CC); + zend_reflection_class_factory(ce, return_value); } /* }}} */ @@ -5207,7 +5514,7 @@ ZEND_METHOD(reflection_property, getDocComment) } GET_REFLECTION_OBJECT_PTR(ref); if (ref->prop.doc_comment) { - RETURN_STRINGL(ref->prop.doc_comment, ref->prop.doc_comment_len, 1); + RETURN_STR_COPY(ref->prop.doc_comment); } RETURN_FALSE; } @@ -5220,15 +5527,11 @@ ZEND_METHOD(reflection_property, setAccessible) reflection_object *intern; zend_bool visible; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &visible) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &visible) == FAILURE) { return; } - intern = (reflection_object *) zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(getThis()); intern->ignore_visibility = visible; } @@ -5246,36 +5549,33 @@ ZEND_METHOD(reflection_extension, export) Constructor. Throws an Exception in case the given extension does not exist */ ZEND_METHOD(reflection_extension, __construct) { - zval *name; + zval name; zval *object; char *lcname; reflection_object *intern; zend_module_entry *module; char *name_str; - int name_len; + size_t name_len; ALLOCA_FLAG(use_heap) - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { return; } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); + lcname = do_alloca(name_len + 1, use_heap); zend_str_tolower_copy(lcname, name_str, name_len); - if (zend_hash_find(&module_registry, lcname, name_len + 1, (void **)&module) == FAILURE) { + if ((module = zend_hash_str_find_ptr(&module_registry, lcname, name_len)) == NULL) { free_alloca(lcname, use_heap); - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Extension %s does not exist", name_str); return; } free_alloca(lcname, use_heap); - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, module->name, 1); - reflection_update_property( object, "name", name); + ZVAL_STRING(&name, module->name); + reflection_update_property(object, "name", &name); intern->ptr = module; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; @@ -5295,8 +5595,8 @@ ZEND_METHOD(reflection_extension, __toString) } GET_REFLECTION_OBJECT_PTR(module); string_init(&str); - _extension_string(&str, module, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _extension_string(&str, module, ""); + RETURN_NEW_STR(str.buf); } /* }}} */ @@ -5307,7 +5607,7 @@ ZEND_METHOD(reflection_extension, getName) if (zend_parse_parameters_none() == FAILURE) { return; } - _default_get_entry(getThis(), "name", sizeof("name"), return_value TSRMLS_CC); + _default_get_entry(getThis(), "name", sizeof("name")-1, return_value); } /* }}} */ @@ -5327,7 +5627,7 @@ ZEND_METHOD(reflection_extension, getVersion) if (module->version == NO_VERSION_YET) { RETURN_NULL(); } else { - RETURN_STRING(module->version, 1); + RETURN_STRING(module->version); } } /* }}} */ @@ -5338,8 +5638,7 @@ ZEND_METHOD(reflection_extension, getFunctions) { reflection_object *intern; zend_module_entry *module; - HashPosition iterator; - zval *function; + zval function; zend_function *fptr; if (zend_parse_parameters_none() == FAILURE) { @@ -5348,31 +5647,26 @@ ZEND_METHOD(reflection_extension, getFunctions) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - zend_hash_internal_pointer_reset_ex(CG(function_table), &iterator); - while (zend_hash_get_current_data_ex(CG(function_table), (void **) &fptr, &iterator) == SUCCESS) { + ZEND_HASH_FOREACH_PTR(CG(function_table), fptr) { if (fptr->common.type==ZEND_INTERNAL_FUNCTION && fptr->internal_function.module == module) { - ALLOC_ZVAL(function); - reflection_function_factory(fptr, NULL, function TSRMLS_CC); - add_assoc_zval(return_value, fptr->common.function_name, function); + reflection_function_factory(fptr, NULL, &function); + zend_hash_update(Z_ARRVAL_P(return_value), fptr->common.function_name, &function); } - zend_hash_move_forward_ex(CG(function_table), &iterator); - } + } ZEND_HASH_FOREACH_END(); } /* }}} */ -static int _addconstant(zend_constant *constant TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ +static int _addconstant(zval *el, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */ { - zval *const_val; + zval const_val; + zend_constant *constant = (zend_constant*)Z_PTR_P(el); zval *retval = va_arg(args, zval*); int number = va_arg(args, int); if (number == constant->module_number) { - ALLOC_ZVAL(const_val); - *const_val = constant->value; - zval_copy_ctor(const_val); - INIT_PZVAL(const_val); - add_assoc_zval_ex(retval, constant->name, constant->name_len, const_val); + ZVAL_DUP(&const_val, &constant->value); + zend_hash_update(Z_ARRVAL_P(retval), constant->name, &const_val); } return 0; } @@ -5391,21 +5685,25 @@ ZEND_METHOD(reflection_extension, getConstants) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - zend_hash_apply_with_arguments(EG(zend_constants) TSRMLS_CC, (apply_func_args_t) _addconstant, 2, return_value, module->module_number); + zend_hash_apply_with_arguments(EG(zend_constants), (apply_func_args_t) _addconstant, 2, return_value, module->module_number); } /* }}} */ /* {{{ _addinientry */ -static int _addinientry(zend_ini_entry *ini_entry TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int _addinientry(zval *el, int num_args, va_list args, zend_hash_key *hash_key) { + zend_ini_entry *ini_entry = (zend_ini_entry*)Z_PTR_P(el); zval *retval = va_arg(args, zval*); int number = va_arg(args, int); if (number == ini_entry->module_number) { if (ini_entry->value) { - add_assoc_stringl(retval, ini_entry->name, ini_entry->value, ini_entry->value_length, 1); + zval zv; + + ZVAL_STR_COPY(&zv, ini_entry->value); + zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &zv); } else { - add_assoc_null(retval, ini_entry->name); + zend_symtable_update(Z_ARRVAL_P(retval), ini_entry->name, &EG(uninitialized_zval)); } } return ZEND_HASH_APPLY_KEEP; @@ -5425,36 +5723,33 @@ ZEND_METHOD(reflection_extension, getINIEntries) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - zend_hash_apply_with_arguments(EG(ini_directives) TSRMLS_CC, (apply_func_args_t) _addinientry, 2, return_value, module->module_number); + zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) _addinientry, 2, return_value, module->module_number); } /* }}} */ /* {{{ add_extension_class */ -static int add_extension_class(zend_class_entry **pce TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) +static int add_extension_class(zval *zv, int num_args, va_list args, zend_hash_key *hash_key) { - zval *class_array = va_arg(args, zval*), *zclass; + zend_class_entry *ce = Z_PTR_P(zv); + zval *class_array = va_arg(args, zval*), zclass; struct _zend_module_entry *module = va_arg(args, struct _zend_module_entry*); int add_reflection_class = va_arg(args, int); - if (((*pce)->type == ZEND_INTERNAL_CLASS) && (*pce)->info.internal.module && !strcasecmp((*pce)->info.internal.module->name, module->name)) { - const char *name; - int nlen; + if ((ce->type == ZEND_INTERNAL_CLASS) && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) { + zend_string *name; - if (zend_binary_strcasecmp((*pce)->name, (*pce)->name_length, hash_key->arKey, hash_key->nKeyLength-1)) { + if (zend_binary_strcasecmp(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key))) { /* This is an class alias, use alias name */ - name = hash_key->arKey; - nlen = hash_key->nKeyLength-1; + name = hash_key->key; } else { /* Use class name */ - name = (*pce)->name; - nlen = (*pce)->name_length; + name = ce->name; } if (add_reflection_class) { - ALLOC_ZVAL(zclass); - zend_reflection_class_factory(*pce, zclass TSRMLS_CC); - add_assoc_zval_ex(class_array, name, nlen+1, zclass); + zend_reflection_class_factory(ce, &zclass); + zend_hash_update(Z_ARRVAL_P(class_array), name, &zclass); } else { - add_next_index_stringl(class_array, name, nlen, 1); + add_next_index_str(class_array, zend_string_copy(name)); } } return ZEND_HASH_APPLY_KEEP; @@ -5474,7 +5769,7 @@ ZEND_METHOD(reflection_extension, getClasses) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) add_extension_class, 3, return_value, module, 1); + zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) add_extension_class, 3, return_value, module, 1); } /* }}} */ @@ -5491,7 +5786,7 @@ ZEND_METHOD(reflection_extension, getClassNames) GET_REFLECTION_OBJECT_PTR(module); array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table) TSRMLS_CC, (apply_func_args_t) add_extension_class, 3, return_value, module, 0); + zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) add_extension_class, 3, return_value, module, 0); } /* }}} */ @@ -5518,32 +5813,45 @@ ZEND_METHOD(reflection_extension, getDependencies) } while(dep->name) { - char *relation; + zend_string *relation; char *rel_type; - int len; + size_t len = 0; switch(dep->type) { - case MODULE_DEP_REQUIRED: - rel_type = "Required"; - break; - case MODULE_DEP_CONFLICTS: - rel_type = "Conflicts"; - break; - case MODULE_DEP_OPTIONAL: - rel_type = "Optional"; - break; - default: - rel_type = "Error"; /* shouldn't happen */ - break; + case MODULE_DEP_REQUIRED: + rel_type = "Required"; + len += sizeof("Required") - 1; + break; + case MODULE_DEP_CONFLICTS: + rel_type = "Conflicts"; + len += sizeof("Conflicts") - 1; + break; + case MODULE_DEP_OPTIONAL: + rel_type = "Optional"; + len += sizeof("Optional") - 1; + break; + default: + rel_type = "Error"; /* shouldn't happen */ + len += sizeof("Error") - 1; + break; + } + + if (dep->rel) { + len += strlen(dep->rel) + 1; + } + + if (dep->version) { + len += strlen(dep->version) + 1; } - len = spprintf(&relation, 0, "%s%s%s%s%s", + relation = zend_string_alloc(len, 0); + snprintf(ZSTR_VAL(relation), ZSTR_LEN(relation) + 1, "%s%s%s%s%s", rel_type, dep->rel ? " " : "", dep->rel ? dep->rel : "", dep->version ? " " : "", dep->version ? dep->version : ""); - add_assoc_stringl(return_value, dep->name, relation, len, 0); + add_assoc_str(return_value, dep->name, relation); dep++; } } @@ -5561,7 +5869,7 @@ ZEND_METHOD(reflection_extension, info) } GET_REFLECTION_OBJECT_PTR(module); - php_info_print_module(module TSRMLS_CC); + php_info_print_module(module); } /* }}} */ @@ -5609,32 +5917,28 @@ ZEND_METHOD(reflection_zend_extension, export) Constructor. Throws an Exception in case the given Zend extension does not exist */ ZEND_METHOD(reflection_zend_extension, __construct) { - zval *name; + zval name; zval *object; reflection_object *intern; zend_extension *extension; char *name_str; - int name_len; + size_t name_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { return; } object = getThis(); - intern = (reflection_object *) zend_object_store_get_object(object TSRMLS_CC); - if (intern == NULL) { - return; - } + intern = Z_REFLECTION_P(object); extension = zend_get_extension(name_str); if (!extension) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + zend_throw_exception_ex(reflection_exception_ptr, 0, "Zend Extension %s does not exist", name_str); return; } - MAKE_STD_ZVAL(name); - ZVAL_STRING(name, extension->name, 1); - reflection_update_property(object, "name", name); + ZVAL_STRING(&name, extension->name); + reflection_update_property(object, "name", &name); intern->ptr = extension; intern->ref_type = REF_TYPE_OTHER; intern->ce = NULL; @@ -5654,8 +5958,8 @@ ZEND_METHOD(reflection_zend_extension, __toString) } GET_REFLECTION_OBJECT_PTR(extension); string_init(&str); - _zend_extension_string(&str, extension, "" TSRMLS_CC); - RETURN_STRINGL(str.string, str.len - 1, 0); + _zend_extension_string(&str, extension, ""); + RETURN_NEW_STR(str.buf); } /* }}} */ @@ -5671,7 +5975,7 @@ ZEND_METHOD(reflection_zend_extension, getName) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->name, 1); + RETURN_STRING(extension->name); } /* }}} */ @@ -5687,7 +5991,11 @@ ZEND_METHOD(reflection_zend_extension, getVersion) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->version ? extension->version : "", 1); + if (extension->version) { + RETURN_STRING(extension->version); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5703,7 +6011,11 @@ ZEND_METHOD(reflection_zend_extension, getAuthor) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->author ? extension->author : "", 1); + if (extension->author) { + RETURN_STRING(extension->author); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5719,7 +6031,11 @@ ZEND_METHOD(reflection_zend_extension, getURL) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->URL ? extension->URL : "", 1); + if (extension->URL) { + RETURN_STRING(extension->URL); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5735,7 +6051,11 @@ ZEND_METHOD(reflection_zend_extension, getCopyright) } GET_REFLECTION_OBJECT_PTR(extension); - RETURN_STRING(extension->copyright ? extension->copyright : "", 1); + if (extension->copyright) { + RETURN_STRING(extension->copyright); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ @@ -5788,7 +6108,6 @@ ZEND_END_ARG_INFO() static const zend_function_entry reflection_function_abstract_functions[] = { ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) - PHP_ABSTRACT_ME(reflection_function, __toString, arginfo_reflection__void) ZEND_ME(reflection_function, inNamespace, arginfo_reflection__void, 0) ZEND_ME(reflection_function, isClosure, arginfo_reflection__void, 0) ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0) @@ -5812,6 +6131,8 @@ static const zend_function_entry reflection_function_abstract_functions[] = { ZEND_ME(reflection_function, getStartLine, arginfo_reflection__void, 0) ZEND_ME(reflection_function, getStaticVariables, arginfo_reflection__void, 0) ZEND_ME(reflection_function, returnsReference, arginfo_reflection__void, 0) + ZEND_ME(reflection_function, hasReturnType, arginfo_reflection__void, 0) + ZEND_ME(reflection_function, getReturnType, arginfo_reflection__void, 0) PHP_FE_END }; @@ -5826,6 +6147,25 @@ static const zend_function_entry reflection_function_functions[] = { PHP_FE_END }; +ZEND_BEGIN_ARG_INFO(arginfo_reflection_generator___construct, 0) + ZEND_ARG_INFO(0, generator) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_generator_trace, 0, 0, 0) + ZEND_ARG_INFO(0, options) +ZEND_END_ARG_INFO() + +static const zend_function_entry reflection_generator_functions[] = { + ZEND_ME(reflection_generator, __construct, arginfo_reflection_generator___construct, 0) + ZEND_ME(reflection_generator, getExecutingLine, arginfo_reflection__void, 0) + ZEND_ME(reflection_generator, getExecutingFile, arginfo_reflection__void, 0) + ZEND_ME(reflection_generator, getTrace, arginfo_reflection_generator_trace, 0) + ZEND_ME(reflection_generator, getFunction, arginfo_reflection__void, 0) + ZEND_ME(reflection_generator, getThis, arginfo_reflection__void, 0) + ZEND_ME(reflection_generator, getExecutingGenerator, arginfo_reflection__void, 0) + PHP_FE_END +}; + ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method_export, 0, 0, 2) ZEND_ARG_INFO(0, class) ZEND_ARG_INFO(0, name) @@ -5873,7 +6213,7 @@ static const zend_function_entry reflection_method_functions[] = { ZEND_ME(reflection_method, invokeArgs, arginfo_reflection_method_invokeArgs, 0) ZEND_ME(reflection_method, getDeclaringClass, arginfo_reflection__void, 0) ZEND_ME(reflection_method, getPrototype, arginfo_reflection__void, 0) - ZEND_ME(reflection_property, setAccessible, arginfo_reflection_method_setAccessible, 0) + ZEND_ME(reflection_method, setAccessible, arginfo_reflection_method_setAccessible, 0) PHP_FE_END }; @@ -5960,6 +6300,7 @@ static const zend_function_entry reflection_class_functions[] = { ZEND_ME(reflection_class, getName, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isInternal, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isUserDefined, arginfo_reflection__void, 0) + ZEND_ME(reflection_class, isAnonymous, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isInstantiable, arginfo_reflection__void, 0) ZEND_ME(reflection_class, isCloneable, arginfo_reflection__void, 0) ZEND_ME(reflection_class, getFileName, arginfo_reflection__void, 0) @@ -6089,6 +6430,8 @@ static const zend_function_entry reflection_parameter_functions[] = { ZEND_ME(reflection_parameter, getDeclaringFunction, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getDeclaringClass, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, getClass, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, hasType, arginfo_reflection__void, 0) + ZEND_ME(reflection_parameter, getType, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isArray, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, isCallable, arginfo_reflection__void, 0) ZEND_ME(reflection_parameter, allowsNull, arginfo_reflection__void, 0) @@ -6102,6 +6445,14 @@ static const zend_function_entry reflection_parameter_functions[] = { PHP_FE_END }; +static const zend_function_entry reflection_type_functions[] = { + ZEND_ME(reflection, __clone, arginfo_reflection__void, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL) + ZEND_ME(reflection_type, allowsNull, arginfo_reflection__void, 0) + ZEND_ME(reflection_type, isBuiltin, arginfo_reflection__void, 0) + ZEND_ME(reflection_type, __toString, arginfo_reflection__void, 0) + PHP_FE_END +}; + ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_extension_export, 0, 0, 1) ZEND_ARG_INFO(0, name) ZEND_ARG_INFO(0, return) @@ -6155,19 +6506,19 @@ const zend_function_entry reflection_ext_functions[] = { /* {{{ */ static zend_object_handlers *zend_std_obj_handlers; /* {{{ _reflection_write_property */ -static void _reflection_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) +static void _reflection_write_property(zval *object, zval *member, zval *value, void **cache_slot) { if ((Z_TYPE_P(member) == IS_STRING) - && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1) + && zend_hash_exists(&Z_OBJCE_P(object)->properties_info, Z_STR_P(member)) && ((Z_STRLEN_P(member) == sizeof("name") - 1 && !memcmp(Z_STRVAL_P(member), "name", sizeof("name"))) || (Z_STRLEN_P(member) == sizeof("class") - 1 && !memcmp(Z_STRVAL_P(member), "class", sizeof("class"))))) { - zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, - "Cannot set read-only property %s::$%s", Z_OBJCE_P(object)->name, Z_STRVAL_P(member)); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Cannot set read-only property %s::$%s", ZSTR_VAL(Z_OBJCE_P(object)->name), Z_STRVAL_P(member)); } else { - zend_std_obj_handlers->write_property(object, member, value, key TSRMLS_CC); + zend_std_obj_handlers->write_property(object, member, value, cache_slot); } } /* }}} */ @@ -6178,42 +6529,53 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ zend_std_obj_handlers = zend_get_std_object_handlers(); memcpy(&reflection_object_handlers, zend_get_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; reflection_object_handlers.write_property = _reflection_write_property; + reflection_object_handlers.get_gc = reflection_get_gc; INIT_CLASS_ENTRY(_reflection_entry, "ReflectionException", reflection_exception_functions); - reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC); + reflection_exception_ptr = zend_register_internal_class_ex(&_reflection_entry, zend_ce_exception); INIT_CLASS_ENTRY(_reflection_entry, "Reflection", reflection_functions); - reflection_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); + reflection_ptr = zend_register_internal_class(&_reflection_entry); INIT_CLASS_ENTRY(_reflection_entry, "Reflector", reflector_functions); - reflector_ptr = zend_register_internal_interface(&_reflection_entry TSRMLS_CC); + reflector_ptr = zend_register_internal_interface(&_reflection_entry); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunctionAbstract", reflection_function_abstract_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_function_abstract_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_function_abstract_ptr, reflector_ptr TSRMLS_CC); - zend_declare_property_string(reflection_function_abstract_ptr, "name", sizeof("name")-1, "", ZEND_ACC_ABSTRACT TSRMLS_CC); + reflection_function_abstract_ptr = zend_register_internal_class(&_reflection_entry); + zend_class_implements(reflection_function_abstract_ptr, 1, reflector_ptr); + zend_declare_property_string(reflection_function_abstract_ptr, "name", sizeof("name")-1, "", ZEND_ACC_ABSTRACT); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionFunction", reflection_function_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC); - zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_function_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr); + zend_declare_property_string(reflection_function_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); REGISTER_REFLECTION_CLASS_CONST_LONG(function, "IS_DEPRECATED", ZEND_ACC_DEPRECATED); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionGenerator", reflection_generator_functions); + _reflection_entry.create_object = reflection_objects_new; + reflection_generator_ptr = zend_register_internal_class(&_reflection_entry); + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionParameter", reflection_parameter_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_parameter_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_parameter_ptr, reflector_ptr TSRMLS_CC); - zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_parameter_ptr = zend_register_internal_class(&_reflection_entry); + zend_class_implements(reflection_parameter_ptr, 1, reflector_ptr); + zend_declare_property_string(reflection_parameter_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); + + INIT_CLASS_ENTRY(_reflection_entry, "ReflectionType", reflection_type_functions); + _reflection_entry.create_object = reflection_objects_new; + reflection_type_ptr = zend_register_internal_class(&_reflection_entry); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionMethod", reflection_method_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr, NULL TSRMLS_CC); - zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_method_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_function_abstract_ptr); + zend_declare_property_string(reflection_method_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); + zend_declare_property_string(reflection_method_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC); REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_STATIC", ZEND_ACC_STATIC); REGISTER_REFLECTION_CLASS_CONST_LONG(method, "IS_PUBLIC", ZEND_ACC_PUBLIC); @@ -6224,24 +6586,24 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionClass", reflection_class_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_class_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_class_ptr, reflector_ptr TSRMLS_CC); - zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_class_ptr = zend_register_internal_class(&_reflection_entry); + zend_class_implements(reflection_class_ptr, 1, reflector_ptr); + zend_declare_property_string(reflection_class_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_IMPLICIT_ABSTRACT", ZEND_ACC_IMPLICIT_ABSTRACT_CLASS); REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_EXPLICIT_ABSTRACT", ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL_CLASS); + REGISTER_REFLECTION_CLASS_CONST_LONG(class, "IS_FINAL", ZEND_ACC_FINAL); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionObject", reflection_object_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_object_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_class_ptr, NULL TSRMLS_CC); + reflection_object_ptr = zend_register_internal_class_ex(&_reflection_entry, reflection_class_ptr); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionProperty", reflection_property_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_property_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_property_ptr, reflector_ptr TSRMLS_CC); - zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_property_ptr = zend_register_internal_class(&_reflection_entry); + zend_class_implements(reflection_property_ptr, 1, reflector_ptr); + zend_declare_property_string(reflection_property_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); + zend_declare_property_string(reflection_property_ptr, "class", sizeof("class")-1, "", ZEND_ACC_PUBLIC); REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_STATIC", ZEND_ACC_STATIC); REGISTER_REFLECTION_CLASS_CONST_LONG(property, "IS_PUBLIC", ZEND_ACC_PUBLIC); @@ -6250,15 +6612,15 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */ INIT_CLASS_ENTRY(_reflection_entry, "ReflectionExtension", reflection_extension_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_extension_ptr, reflector_ptr TSRMLS_CC); - zend_declare_property_string(reflection_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_extension_ptr = zend_register_internal_class(&_reflection_entry); + zend_class_implements(reflection_extension_ptr, 1, reflector_ptr); + zend_declare_property_string(reflection_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); INIT_CLASS_ENTRY(_reflection_entry, "ReflectionZendExtension", reflection_zend_extension_functions); _reflection_entry.create_object = reflection_objects_new; - reflection_zend_extension_ptr = zend_register_internal_class(&_reflection_entry TSRMLS_CC); - reflection_register_implement(reflection_zend_extension_ptr, reflector_ptr TSRMLS_CC); - zend_declare_property_string(reflection_zend_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC TSRMLS_CC); + reflection_zend_extension_ptr = zend_register_internal_class(&_reflection_entry); + zend_class_implements(reflection_zend_extension_ptr, 1, reflector_ptr); + zend_declare_property_string(reflection_zend_extension_ptr, "name", sizeof("name")-1, "", ZEND_ACC_PUBLIC); return SUCCESS; } /* }}} */ @@ -6282,7 +6644,7 @@ zend_module_entry reflection_module_entry = { /* {{{ */ NULL, NULL, PHP_MINFO(reflection), - "$Id$", + PHP_REFLECTION_VERSION, STANDARD_MODULE_PROPERTIES }; /* }}} */ diff --git a/ext/reflection/php_reflection.h b/ext/reflection/php_reflection.h index 64d4141edd..b4f2cd7bc0 100644 --- a/ext/reflection/php_reflection.h +++ b/ext/reflection/php_reflection.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -26,6 +26,8 @@ extern zend_module_entry reflection_module_entry; #define phpext_reflection_ptr &reflection_module_entry +#define PHP_REFLECTION_VERSION PHP_VERSION + BEGIN_EXTERN_C() /* Class entry pointers */ @@ -35,6 +37,7 @@ extern PHPAPI zend_class_entry *reflection_ptr; extern PHPAPI zend_class_entry *reflection_function_abstract_ptr; extern PHPAPI zend_class_entry *reflection_function_ptr; extern PHPAPI zend_class_entry *reflection_parameter_ptr; +extern PHPAPI zend_class_entry *reflection_type_ptr; extern PHPAPI zend_class_entry *reflection_class_ptr; extern PHPAPI zend_class_entry *reflection_object_ptr; extern PHPAPI zend_class_entry *reflection_method_ptr; @@ -42,8 +45,8 @@ extern PHPAPI zend_class_entry *reflection_property_ptr; extern PHPAPI zend_class_entry *reflection_extension_ptr; extern PHPAPI zend_class_entry *reflection_zend_extension_ptr; -PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object TSRMLS_DC); - +PHPAPI void zend_reflection_class_factory(zend_class_entry *ce, zval *object); + END_EXTERN_C() #endif /* PHP_REFLECTION_H */ diff --git a/ext/reflection/tests/004.phpt b/ext/reflection/tests/004.phpt index 2c81c506be..41632aa3ba 100644 --- a/ext/reflection/tests/004.phpt +++ b/ext/reflection/tests/004.phpt @@ -36,7 +36,8 @@ try { } echo "===DONE===\n";?> ---EXPECT-- +--EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; a has a deprecated constructor in %s on line %d Non-object passed to Invoke() Given object is not an instance of the class this method was declared in ===DONE=== diff --git a/ext/reflection/tests/005.phpt b/ext/reflection/tests/005.phpt index e257699b6f..e40fcc3099 100644 --- a/ext/reflection/tests/005.phpt +++ b/ext/reflection/tests/005.phpt @@ -2,7 +2,6 @@ ReflectionMethod::getDocComment() uses wrong comment block --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/009.phpt b/ext/reflection/tests/009.phpt index b54e89e5bf..c6a252cfca 100644 --- a/ext/reflection/tests/009.phpt +++ b/ext/reflection/tests/009.phpt @@ -2,7 +2,6 @@ ReflectionFunction basic tests --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php @@ -76,7 +75,7 @@ int(6) --getEndline-- int(8) --getDocComment-- -string(11) "/** +string(%d) "/** hoho */" --getStaticVariables-- @@ -93,17 +92,17 @@ bool(false) --getParameters-- array(3) { [0]=> - &object(ReflectionParameter)#2 (1) { + object(ReflectionParameter)#2 (1) { ["name"]=> string(1) "a" } [1]=> - &object(ReflectionParameter)#3 (1) { + object(ReflectionParameter)#3 (1) { ["name"]=> string(1) "b" } [2]=> - &object(ReflectionParameter)#4 (1) { + object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "c" } diff --git a/ext/reflection/tests/025.phpt b/ext/reflection/tests/025.phpt index 92002007b6..0259d66bd3 100644 --- a/ext/reflection/tests/025.phpt +++ b/ext/reflection/tests/025.phpt @@ -4,7 +4,6 @@ ReflectionFunction basic tests <?php extension_loaded('reflection') or die('skip'); ?> --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php @@ -78,7 +77,7 @@ int(6) --getEndline-- int(8) --getDocComment-- -string(11) "/** +string(%d) "/** hoho */" --getStaticVariables-- @@ -95,17 +94,17 @@ bool(false) --getParameters-- array(3) { [0]=> - &object(ReflectionParameter)#2 (1) { + object(ReflectionParameter)#2 (1) { ["name"]=> string(1) "a" } [1]=> - &object(ReflectionParameter)#3 (1) { + object(ReflectionParameter)#3 (1) { ["name"]=> string(1) "b" } [2]=> - &object(ReflectionParameter)#4 (1) { + object(ReflectionParameter)#4 (1) { ["name"]=> string(1) "c" } diff --git a/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt b/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt index 6b440cfe06..bbe5fdbaec 100644 --- a/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt +++ b/ext/reflection/tests/ReflectionClass_CannotClone_basic.phpt @@ -5,11 +5,14 @@ Stefan Koopmanschap <stefan@phpgg.nl> TestFest PHP|Tek --SKIPIF-- <?php -if (!extension_loaded('reflection)) print 'skip'; +if (!extension_loaded('reflection')) print 'skip'; ?> --FILE-- <?php $rc = new ReflectionClass("stdClass"); $rc2 = clone($rc); --EXPECTF-- -Fatal error: Trying to clone an uncloneable object of class ReflectionClass in %s on line %d +Fatal error: Uncaught Error: Trying to clone an uncloneable object of class ReflectionClass in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt b/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt index 1f5ba432c3..c572796ae8 100644 --- a/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt +++ b/ext/reflection/tests/ReflectionClass_getConstructor_basic.phpt @@ -64,7 +64,11 @@ foreach ($classes as $class) { ?> --EXPECTF-- -Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OldCtor has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; B has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; C has a deprecated constructor in %s on line %d Constructor of NewCtor: __construct Constructor of ExtendsNewCtor: __construct Constructor of OldCtor: OldCtor diff --git a/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt index efa7e9a10a..624829f014 100644 --- a/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt +++ b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt @@ -5,7 +5,6 @@ Robin Fernandes <robinf@php.net> Steve Seear <stevseea@php.net> --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php /** diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt index 74044f7531..f1cac44e95 100644 --- a/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_003.phpt @@ -52,7 +52,7 @@ The result is an array in which each element is an object (an instance of Reflec Var_dumping this array shows that the elements are referenced. By what? array(1) { ["I"]=> - &object(ReflectionClass)#%d (1) { + object(ReflectionClass)#%d (1) { ["name"]=> string(1) "I" } @@ -66,4 +66,4 @@ array(1) { ["x"]=> int(1) } -}
\ No newline at end of file +} diff --git a/ext/reflection/tests/ReflectionClass_getMethods_001.phpt b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt index ce5c980c60..1e11dee2f3 100644 --- a/ext/reflection/tests/ReflectionClass_getMethods_001.phpt +++ b/ext/reflection/tests/ReflectionClass_getMethods_001.phpt @@ -39,14 +39,14 @@ foreach($classes as $class) { Reflecting on class pubf: array(2) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "f" [%u|b%"class"]=> %unicode|string%(4) "pubf" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -56,14 +56,14 @@ array(2) { Reflecting on class subpubf: array(2) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "f" [%u|b%"class"]=> %unicode|string%(4) "pubf" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -73,14 +73,14 @@ array(2) { Reflecting on class protf: array(2) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "f" [%u|b%"class"]=> %unicode|string%(5) "protf" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -90,14 +90,14 @@ array(2) { Reflecting on class subprotf: array(2) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "f" [%u|b%"class"]=> %unicode|string%(5) "protf" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -107,14 +107,14 @@ array(2) { Reflecting on class privf: array(2) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "f" [%u|b%"class"]=> %unicode|string%(5) "privf" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -124,14 +124,14 @@ array(2) { Reflecting on class subprivf: array(2) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "f" [%u|b%"class"]=> %unicode|string%(5) "privf" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> diff --git a/ext/reflection/tests/ReflectionClass_getMethods_002.phpt b/ext/reflection/tests/ReflectionClass_getMethods_002.phpt index b25222563b..fae86e1642 100644 --- a/ext/reflection/tests/ReflectionClass_getMethods_002.phpt +++ b/ext/reflection/tests/ReflectionClass_getMethods_002.phpt @@ -13,6 +13,6 @@ $rc->getMethods('X', true); ?> --EXPECTF-- Test invalid arguments: -Warning: ReflectionClass::getMethods() expects parameter 1 to be long, string given in %s on line 4 +Warning: ReflectionClass::getMethods() expects parameter 1 to be integer, string given in %s on line 4 Warning: ReflectionClass::getMethods() expects at most 1 parameter, 2 given in %s on line 5 diff --git a/ext/reflection/tests/ReflectionClass_getMethods_003.phpt b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt index 435f5d2d8d..885bd908f1 100644 --- a/ext/reflection/tests/ReflectionClass_getMethods_003.phpt +++ b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt @@ -43,28 +43,28 @@ No methods:array(0) { } Public methods:array(4) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(5) "pubf1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(5) "pubf2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "pubsf1" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "pubsf2" ["class"]=> @@ -73,28 +73,28 @@ Public methods:array(4) { } Private methods:array(4) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "privf1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "privf2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(7) "privsf1" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(7) "privsf2" ["class"]=> @@ -103,42 +103,42 @@ Private methods:array(4) { } Public or static methods:array(6) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(5) "pubf1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(5) "pubf2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "pubsf1" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "pubsf2" ["class"]=> string(1) "C" } [4]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(7) "privsf1" ["class"]=> string(1) "C" } [5]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(7) "privsf2" ["class"]=> @@ -147,42 +147,42 @@ Public or static methods:array(6) { } Private or static methods:array(6) { [0]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "privf1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "privf2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "pubsf1" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(6) "pubsf2" ["class"]=> string(1) "C" } [4]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(7) "privsf1" ["class"]=> string(1) "C" } [5]=> - &object(ReflectionMethod)#%d (2) { + object(ReflectionMethod)#%d (2) { ["name"]=> string(7) "privsf2" ["class"]=> diff --git a/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt index 65f23c935f..68189db2bb 100644 --- a/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt @@ -30,8 +30,8 @@ dump_modifiers('g'); --EXPECT-- int(0) int(32) +int(4) int(64) -int(128) int(524288) -int(524416) +int(524352) int(0) diff --git a/ext/reflection/tests/ReflectionClass_getName_error1.phpt b/ext/reflection/tests/ReflectionClass_getName_error1.phpt index 5590137f89..dcdfcdf98f 100644 --- a/ext/reflection/tests/ReflectionClass_getName_error1.phpt +++ b/ext/reflection/tests/ReflectionClass_getName_error1.phpt @@ -5,4 +5,7 @@ ReflectionClass::getName - forbid static invocation ReflectionClass::getName(); ?> --EXPECTF-- -Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2 +Fatal error: Uncaught Error: Non-static method ReflectionClass::getName() cannot be called statically in %s:2 +Stack trace: +#0 {main} + thrown in %s on line 2 diff --git a/ext/reflection/tests/ReflectionClass_getProperties_001.phpt b/ext/reflection/tests/ReflectionClass_getProperties_001.phpt index b4f99ca68f..cd4a29d450 100644 --- a/ext/reflection/tests/ReflectionClass_getProperties_001.phpt +++ b/ext/reflection/tests/ReflectionClass_getProperties_001.phpt @@ -39,14 +39,14 @@ foreach($classes as $class) { Reflecting on class pubf: array(2) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "a" [%u|b%"class"]=> %unicode|string%(4) "pubf" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -56,14 +56,14 @@ array(2) { Reflecting on class subpubf: array(2) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "a" [%u|b%"class"]=> %unicode|string%(4) "pubf" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -73,14 +73,14 @@ array(2) { Reflecting on class protf: array(2) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "a" [%u|b%"class"]=> %unicode|string%(5) "protf" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -90,14 +90,14 @@ array(2) { Reflecting on class subprotf: array(2) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "a" [%u|b%"class"]=> %unicode|string%(5) "protf" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> @@ -107,14 +107,14 @@ array(2) { Reflecting on class privf: array(2) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "a" [%u|b%"class"]=> %unicode|string%(5) "privf" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { [%u|b%"name"]=> %unicode|string%(1) "s" [%u|b%"class"]=> diff --git a/ext/reflection/tests/ReflectionClass_getProperties_002.phpt b/ext/reflection/tests/ReflectionClass_getProperties_002.phpt index c21cff24f5..fc4d5648a4 100644 --- a/ext/reflection/tests/ReflectionClass_getProperties_002.phpt +++ b/ext/reflection/tests/ReflectionClass_getProperties_002.phpt @@ -12,6 +12,6 @@ $rc->getProperties('X', true); ?> --EXPECTF-- Test invalid arguments: -Warning: ReflectionClass::getProperties() expects parameter 1 to be long, string given in %s on line 4 +Warning: ReflectionClass::getProperties() expects parameter 1 to be integer, string given in %s on line 4 Warning: ReflectionClass::getProperties() expects at most 1 parameter, 2 given in %s on line 5 diff --git a/ext/reflection/tests/ReflectionClass_getProperties_003.phpt b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt index b4f9a774db..ac16a68349 100644 --- a/ext/reflection/tests/ReflectionClass_getProperties_003.phpt +++ b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt @@ -41,28 +41,28 @@ No properties:array(0) { } Public properties:array(4) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pub1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pub2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pubs" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "pubs2" ["class"]=> @@ -71,28 +71,28 @@ Public properties:array(4) { } Private properties:array(4) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "priv1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "priv2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(6) "privs1" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(6) "privs2" ["class"]=> @@ -101,42 +101,42 @@ Private properties:array(4) { } Public or static properties:array(6) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pub1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pub2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pubs" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "pubs2" ["class"]=> string(1) "C" } [4]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(6) "privs1" ["class"]=> string(1) "C" } [5]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(6) "privs2" ["class"]=> @@ -145,42 +145,42 @@ Public or static properties:array(6) { } Private or static properties:array(6) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "priv1" ["class"]=> string(1) "C" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "priv2" ["class"]=> string(1) "C" } [2]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(4) "pubs" ["class"]=> string(1) "C" } [3]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "pubs2" ["class"]=> string(1) "C" } [4]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(6) "privs1" ["class"]=> string(1) "C" } [5]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(6) "privs2" ["class"]=> diff --git a/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001_2_4.phpt b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001_2_4.phpt index 8bb62d95f1..02f7595cb4 100644 --- a/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001_2_4.phpt +++ b/ext/reflection/tests/ReflectionClass_getStaticPropertyValue_001_2_4.phpt @@ -54,7 +54,7 @@ try { Retrieving static values from A: string(13) "default value" -Fatal error: Uncaught exception 'ReflectionException' with message 'Class A does not have a property named ' in %sReflectionClass_getStaticPropertyValue_001_2_4.php:%d +Fatal error: Uncaught ReflectionException: Class A does not have a property named in %sReflectionClass_getStaticPropertyValue_001_2_4.php:%d Stack trace: #0 %sReflectionClass_getStaticPropertyValue_001_2_4.php(%d): ReflectionClass->getStaticPropertyValue('\x00A\x00privateOverr...') #1 {main} diff --git a/ext/reflection/tests/ReflectionClass_isAnonymous.phpt b/ext/reflection/tests/ReflectionClass_isAnonymous.phpt new file mode 100644 index 0000000000..deff25aec2 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isAnonymous.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionClass::isAnonymous() method +--FILE-- +<?php + +class TestClass {} + +$declaredClass = new ReflectionClass('TestClass'); +$anonymousClass = new ReflectionClass(new class {}); + +var_dump($declaredClass->isAnonymous()); +var_dump($anonymousClass->isAnonymous()); + +?> +--EXPECT-- +bool(false) +bool(true) diff --git a/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt b/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt index f1042cc130..361708a315 100644 --- a/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt +++ b/ext/reflection/tests/ReflectionClass_isCloneable_001.phpt @@ -68,4 +68,7 @@ Internal class - XMLWriter bool(false) bool(false) -Fatal error: Trying to clone an uncloneable object of class XMLWriter in %s on line %d +Fatal error: Uncaught Error: Trying to clone an uncloneable object of class XMLWriter in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/ext/reflection/tests/ReflectionClass_isInstance_error.phpt b/ext/reflection/tests/ReflectionClass_isInstance_error.phpt index 2c4f49b7d0..eb3043f25d 100644 --- a/ext/reflection/tests/ReflectionClass_isInstance_error.phpt +++ b/ext/reflection/tests/ReflectionClass_isInstance_error.phpt @@ -26,7 +26,7 @@ NULL Warning: ReflectionClass::isInstance() expects parameter 1 to be object, %s given in %s on line 9 NULL -Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 10 +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, float given in %s on line 10 NULL Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 11 diff --git a/ext/reflection/tests/ReflectionClass_isInstantiable_error.phpt b/ext/reflection/tests/ReflectionClass_isInstantiable_error.phpt index 52be239121..5263643023 100644 --- a/ext/reflection/tests/ReflectionClass_isInstantiable_error.phpt +++ b/ext/reflection/tests/ReflectionClass_isInstantiable_error.phpt @@ -12,6 +12,8 @@ var_dump($reflectionClass->IsInstantiable(0, null)); ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; privateCtorOld has a deprecated constructor in %s on line %d + Warning: ReflectionClass::isInstantiable() expects exactly 0 parameters, 1 given in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionClass_isInstantiable_variation.phpt b/ext/reflection/tests/ReflectionClass_isInstantiable_variation.phpt index 1cf3e613e8..e334a90a72 100644 --- a/ext/reflection/tests/ReflectionClass_isInstantiable_variation.phpt +++ b/ext/reflection/tests/ReflectionClass_isInstantiable_variation.phpt @@ -41,6 +41,11 @@ foreach($classes as $class ) { ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; publicCtorOld has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; protectedCtorOld has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; privateCtorOld has a deprecated constructor in %s on line %d Is noCtor instantiable? bool(true) Is publicCtorNew instantiable? bool(true) Is protectedCtorNew instantiable? bool(false) diff --git a/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt index 4936413ef6..42dc647a02 100644 --- a/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt +++ b/ext/reflection/tests/ReflectionClass_isIterateable_001.phpt @@ -86,4 +86,7 @@ NULL Test static invocation: -Fatal error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s on line 43
\ No newline at end of file +Fatal error: Uncaught Error: Non-static method ReflectionClass::isIterateable() cannot be called statically in %s:43 +Stack trace: +#0 {main} + thrown in %s on line 43
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_isSubclassOf_error1.phpt b/ext/reflection/tests/ReflectionClass_isSubclassOf_error1.phpt index 2fabd023e6..bb4f96818a 100644 --- a/ext/reflection/tests/ReflectionClass_isSubclassOf_error1.phpt +++ b/ext/reflection/tests/ReflectionClass_isSubclassOf_error1.phpt @@ -9,7 +9,7 @@ var_dump($rc->isSubclassOf('X')); ?> --EXPECTF-- -Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:5 +Fatal error: Uncaught ReflectionException: Class X does not exist in %s:5 Stack trace: #0 %s(5): ReflectionClass->isSubclassOf('X') #1 {main} diff --git a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt index 941bfe5f2b..7f62b565a2 100644 --- a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt +++ b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt @@ -37,8 +37,8 @@ int(0) bool(true) bool(false) bool(false) -int(64) +int(4) bool(false) bool(true) bool(false) -int(128)
\ No newline at end of file +int(64)
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt index 981d67519a..d3a426de4c 100644 --- a/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt @@ -71,6 +71,7 @@ try { } ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d In constructor of class A In constructor of class A object(A)#%d (0) { @@ -95,4 +96,4 @@ Access to non-public constructor of class C Access to non-public constructor of class D object(E)#%d (0) { } -Class E does not have a constructor, so you cannot pass any constructor arguments
\ No newline at end of file +Class E does not have a constructor, so you cannot pass any constructor arguments diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt index dd6f4384ee..2754b4c8e3 100644 --- a/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_002.phpt @@ -17,4 +17,8 @@ var_dump($a); ?> --EXPECTF-- -Catchable fatal error: Argument 1 passed to ReflectionClass::newInstanceArgs() must be of the type array, string given in %s on line 8 +Fatal error: Uncaught TypeError: Argument 1 passed to ReflectionClass::newInstanceArgs() must be of the type array, string given in %s:8 +Stack trace: +#0 %s(%d): ReflectionClass->newInstanceArgs('x') +#1 {main} + thrown in %s on line 8 diff --git a/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt b/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt index dfe3e7f8f7..334efc3a50 100644 --- a/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt @@ -31,7 +31,7 @@ object(stdClass)#%d (0) { object(DateTime)#%d (0) { } -Fatal error: Uncaught exception 'ReflectionException' with message 'Class Generator is an internal class marked as final that cannot be instantiated without invoking its constructor' in %sReflectionClass_newInstanceWithoutConstructor.php:%d +Fatal error: Uncaught ReflectionException: Class Generator is an internal class marked as final that cannot be instantiated without invoking its constructor in %sReflectionClass_newInstanceWithoutConstructor.php:%d Stack trace: #0 %sReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor() #1 {main} diff --git a/ext/reflection/tests/ReflectionClass_newInstance_001.phpt b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt index 3cdb5d76b7..afa278a9a1 100644 --- a/ext/reflection/tests/ReflectionClass_newInstance_001.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt @@ -71,6 +71,7 @@ try { } ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d In constructor of class A In constructor of class A object(A)#%d (0) { @@ -95,4 +96,4 @@ Access to non-public constructor of class C Access to non-public constructor of class D object(E)#%d (0) { } -Class E does not have a constructor, so you cannot pass any constructor arguments
\ No newline at end of file +Class E does not have a constructor, so you cannot pass any constructor arguments diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001_2_4.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001_2_4.phpt index dc13bf562d..6720d2daa2 100644 --- a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001_2_4.phpt +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_001_2_4.phpt @@ -54,7 +54,7 @@ try { --EXPECTF-- Set static values in A: -Fatal error: Uncaught exception 'ReflectionException' with message 'Class A does not have a property named ' in %sReflectionClass_setStaticPropertyValue_001_2_4.php:%d +Fatal error: Uncaught ReflectionException: Class A does not have a property named in %sReflectionClass_setStaticPropertyValue_001_2_4.php:%d Stack trace: #0 %sReflectionClass_setStaticPropertyValue_001_2_4.php(%d): ReflectionClass->setStaticPropertyValue('\x00A\x00privateOverr...', 'new value 1') #1 {main} diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index 508530a547..b9a9b0d559 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -14,14 +14,14 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { - Constants [3] { Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } - Constant [ integer IS_FINAL ] { 64 } + Constant [ integer IS_FINAL ] { 4 } } - Static properties [0] { } - Static methods [1] { - Method [ <internal:Reflection> static public method export ] { + Method [ <internal:Reflection, prototype Reflector> static public method export ] { - Parameters [2] { Parameter #0 [ <required> $argument ] @@ -34,7 +34,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { Property [ <default> public $name ] } - - Methods [49] { + - Methods [50] { Method [ <internal:Reflection> final private method __clone ] { - Parameters [0] { @@ -48,7 +48,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { } } - Method [ <internal:Reflection> public method __toString ] { + Method [ <internal:Reflection, prototype Reflector> public method __toString ] { - Parameters [0] { } @@ -72,6 +72,12 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { } } + Method [ <internal:Reflection> public method isAnonymous ] { + + - Parameters [0] { + } + } + Method [ <internal:Reflection> public method isInstantiable ] { - Parameters [0] { diff --git a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt index 9eae206c50..94071de5ab 100644 --- a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt +++ b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt @@ -5,12 +5,29 @@ Gerrit "Remi" te Sligte <remi@wolerized.com> Leon Luijkx <leon@phpgg.nl> --FILE-- <?php -$obj = new ReflectionExtension(); -$test = $obj instanceof ReflectionExtension; -var_dump($test); +try { + $obj = new ReflectionExtension(); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try { + $obj = new ReflectionExtension('foo', 'bar'); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try { + $obj = new ReflectionExtension([]); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + ?> ==DONE== --EXPECTF-- -Warning: ReflectionExtension::__construct() expects exactly %d parameter, %d given in %s.php on line %d -bool(true) +Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given +Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given +Ok - ReflectionExtension::__construct() expects parameter 1 to be string, array given ==DONE== diff --git a/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt index dfec951f79..3fea08c43f 100644 --- a/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt @@ -9,12 +9,14 @@ var_dump($standard->getClassNames()); ?> ==DONE== --EXPECTF-- -array(3) { +array(4) { [0]=> %s(22) "__PHP_Incomplete_Class" [1]=> %s(15) "php_user_filter" [2]=> %s(9) "Directory" + [3]=> + %s(14) "AssertionError" } ==DONE== diff --git a/ext/reflection/tests/ReflectionExtension_getClassNames_variation1.phpt b/ext/reflection/tests/ReflectionExtension_getClassNames_variation1.phpt index cd5dc0b281..91912b9220 100644 --- a/ext/reflection/tests/ReflectionExtension_getClassNames_variation1.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClassNames_variation1.phpt @@ -2,10 +2,14 @@ ReflectionExtension::getClassNames() method on an extension with no classes --CREDITS-- Felix De Vliegher <felix.devliegher@gmail.com> +--SKIPIF-- +<?php +extension_loaded('ctype') or die("skip Requires 'ctype' extension"); +?> --FILE-- <?php -$ereg = new ReflectionExtension('ereg'); -var_dump($ereg->getClassNames()); +$extension = new ReflectionExtension('ctype'); +var_dump($extension->getClassNames()); ?> ==DONE== --EXPECT-- diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt index 5df9e08c69..4eda22a3f9 100644 --- a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt @@ -9,64 +9,74 @@ var_dump($ext->getClasses()); ?> ==DONE== --EXPECT-- -array(12) { +array(14) { ["ReflectionException"]=> - &object(ReflectionClass)#2 (1) { + object(ReflectionClass)#2 (1) { ["name"]=> string(19) "ReflectionException" } ["Reflection"]=> - &object(ReflectionClass)#3 (1) { + object(ReflectionClass)#3 (1) { ["name"]=> string(10) "Reflection" } ["Reflector"]=> - &object(ReflectionClass)#4 (1) { + object(ReflectionClass)#4 (1) { ["name"]=> string(9) "Reflector" } ["ReflectionFunctionAbstract"]=> - &object(ReflectionClass)#5 (1) { + object(ReflectionClass)#5 (1) { ["name"]=> string(26) "ReflectionFunctionAbstract" } ["ReflectionFunction"]=> - &object(ReflectionClass)#6 (1) { + object(ReflectionClass)#6 (1) { ["name"]=> string(18) "ReflectionFunction" } + ["ReflectionGenerator"]=> + object(ReflectionClass)#7 (1) { + ["name"]=> + string(19) "ReflectionGenerator" + } ["ReflectionParameter"]=> - &object(ReflectionClass)#7 (1) { + object(ReflectionClass)#8 (1) { ["name"]=> string(19) "ReflectionParameter" } + ["ReflectionType"]=> + object(ReflectionClass)#9 (1) { + ["name"]=> + string(14) "ReflectionType" + } ["ReflectionMethod"]=> - &object(ReflectionClass)#8 (1) { + object(ReflectionClass)#10 (1) { ["name"]=> string(16) "ReflectionMethod" } ["ReflectionClass"]=> - &object(ReflectionClass)#9 (1) { + object(ReflectionClass)#11 (1) { ["name"]=> string(15) "ReflectionClass" } ["ReflectionObject"]=> - &object(ReflectionClass)#10 (1) { + object(ReflectionClass)#12 (1) { ["name"]=> string(16) "ReflectionObject" } ["ReflectionProperty"]=> - &object(ReflectionClass)#11 (1) { + object(ReflectionClass)#13 (1) { ["name"]=> string(18) "ReflectionProperty" } ["ReflectionExtension"]=> - &object(ReflectionClass)#12 (1) { + object(ReflectionClass)#14 (1) { ["name"]=> string(19) "ReflectionExtension" } ["ReflectionZendExtension"]=> - &object(ReflectionClass)#13 (1) { + object(ReflectionClass)#15 (1) { ["name"]=> string(23) "ReflectionZendExtension" } diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt index c8e0a17a9d..0e2e8a3681 100644 --- a/ext/reflection/tests/ReflectionFunction_construct.001.phpt +++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt @@ -6,18 +6,37 @@ Steve Seear <stevseea@php.net> --FILE-- <?php -$a = new ReflectionFunction(array(1, 2, 3)); +try { + $a = new ReflectionFunction(array(1, 2, 3)); + echo "exception not thrown.".PHP_EOL; +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} try { $a = new ReflectionFunction('nonExistentFunction'); -} catch (Exception $e) { - echo $e->getMessage(); +} catch (ReflectionException $e) { + echo $e->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction(); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction(1, 2); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction([]); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } -$a = new ReflectionFunction(); -$a = new ReflectionFunction(1, 2); + ?> --EXPECTF-- -Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d +Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given Function nonExistentFunction() does not exist -Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d - -Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d +Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given +Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given +Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given diff --git a/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt index 68d1d9d3a1..2d5bb928b2 100644 --- a/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt +++ b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt @@ -5,7 +5,6 @@ Robin Fernandes <robinf@php.net> Steve Seear <stevseea@php.net> --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/ReflectionFunction_isDeprecated_basic.phpt b/ext/reflection/tests/ReflectionFunction_isDeprecated_basic.phpt index 4148fada0c..7b37b939e4 100644 --- a/ext/reflection/tests/ReflectionFunction_isDeprecated_basic.phpt +++ b/ext/reflection/tests/ReflectionFunction_isDeprecated_basic.phpt @@ -3,13 +3,10 @@ ReflectionFunction::isDeprecated --CREDITS-- Stefan Koopmanschap <stefan@phpgg.nl> TestFest PHP|Tek ---SKIPIF-- -<?php -if (!extension_loaded('reflection') || !defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) print 'skip'; -?> --FILE-- <?php -$rc = new ReflectionFunction('ereg'); +// We currently don't have any deprecated functions :/ +$rc = new ReflectionFunction('var_dump'); var_dump($rc->isDeprecated()); --EXPECTF-- -bool(true) +bool(false) diff --git a/ext/reflection/tests/ReflectionGenerator_basic.phpt b/ext/reflection/tests/ReflectionGenerator_basic.phpt new file mode 100644 index 0000000000..6f35b6c244 --- /dev/null +++ b/ext/reflection/tests/ReflectionGenerator_basic.phpt @@ -0,0 +1,91 @@ +--TEST-- +ReflectionGenerator basic test +--FILE-- +<?php + +function foo() { + yield; +} + +$gens = [ + (new class() { + function a() { + yield from foo(); + } + })->a(), + (function() { + yield; + })(), + foo(), +]; + +foreach ($gens as $gen) { + var_dump($gen); + + $gen->valid(); // start Generator + $ref = new ReflectionGenerator($gen); + + var_dump($ref->getTrace()); + var_dump($ref->getExecutingLine()); + var_dump($ref->getExecutingFile()); + var_dump($ref->getExecutingGenerator()); + var_dump($ref->getFunction()); + var_dump($ref->getThis()); +} + +?> +--EXPECTF-- +object(Generator)#2 (0) { +} +array(1) { + [0]=> + array(4) { + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) + ["function"]=> + string(3) "foo" + ["args"]=> + array(0) { + } + } +} +int(%d) +string(%d) "%sReflectionGenerator_basic.%s" +object(Generator)#6 (0) { +} +object(ReflectionMethod)#8 (2) { + ["name"]=> + string(1) "a" + ["class"]=> + string(%d) "class@anonymous%s" +} +object(class@anonymous)#1 (0) { +} +object(Generator)#4 (0) { +} +array(0) { +} +int(%d) +string(%d) "%sReflectionGenerator_basic.%s" +object(Generator)#4 (0) { +} +object(ReflectionFunction)#7 (1) { + ["name"]=> + string(9) "{closure}" +} +NULL +object(Generator)#5 (0) { +} +array(0) { +} +int(%d) +string(%d) "%sReflectionGenerator_basic.%s" +object(Generator)#5 (0) { +} +object(ReflectionFunction)#8 (1) { + ["name"]=> + string(3) "foo" +} +NULL diff --git a/ext/reflection/tests/ReflectionGenerator_getTrace.phpt b/ext/reflection/tests/ReflectionGenerator_getTrace.phpt new file mode 100644 index 0000000000..05a46009e8 --- /dev/null +++ b/ext/reflection/tests/ReflectionGenerator_getTrace.phpt @@ -0,0 +1,53 @@ +--TEST-- +ReflectionGenerator::getTrace() over multiple Generators +--FILE-- +<?php + +function foo() { + yield 1; + yield 2; +} + +function bar() +{ + yield from foo(); +} + +function baz() +{ + yield from bar(); +} + +$gen = baz(); +$gen->valid(); + +var_dump((new ReflectionGenerator($gen))->getTrace()); + +?> +--EXPECTF-- +array(2) { + [0]=> + array(4) { + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) + ["function"]=> + string(3) "foo" + ["args"]=> + array(0) { + } + } + [1]=> + array(4) { + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) + ["function"]=> + string(3) "bar" + ["args"]=> + array(0) { + } + } +} diff --git a/ext/reflection/tests/ReflectionGenerator_in_Generator.phpt b/ext/reflection/tests/ReflectionGenerator_in_Generator.phpt new file mode 100644 index 0000000000..a227e1a213 --- /dev/null +++ b/ext/reflection/tests/ReflectionGenerator_in_Generator.phpt @@ -0,0 +1,69 @@ +--TEST-- +ReflectionGenerator while being currently executed +--FILE-- +<?php + +function call(ReflectionGenerator $ref, $method, $rec = true) { + if ($rec) { + call($ref, $method, false); + return; + } + var_dump($ref->$method()); +} + +function doCalls(ReflectionGenerator $ref) { + call($ref, "getTrace"); + call($ref, "getExecutingLine"); + call($ref, "getExecutingFile"); + call($ref, "getExecutingGenerator"); + call($ref, "getFunction"); + call($ref, "getThis"); +} + +($gen = (function() use (&$gen) { + $ref = new ReflectionGenerator($gen); + + doCalls($ref); + + yield from (function() use ($ref) { + doCalls($ref); + yield; // Generator ! + })(); +})())->next(); + +?> +--EXPECTF-- +array(0) { +} +int(%d) +string(%d) "%sReflectionGenerator_in_Generator.%s" +object(Generator)#2 (0) { +} +object(ReflectionFunction)#4 (1) { + ["name"]=> + string(9) "{closure}" +} +NULL +array(1) { + [0]=> + array(4) { + ["file"]=> + string(%d) "%s" + ["line"]=> + int(%d) + ["function"]=> + string(9) "{closure}" + ["args"]=> + array(0) { + } + } +} +int(%d) +string(%d) "%sReflectionGenerator_in_Generator.%s" +object(Generator)#5 (0) { +} +object(ReflectionFunction)#6 (1) { + ["name"]=> + string(9) "{closure}" +} +NULL diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt index a5164190ca..627dc96f32 100644 --- a/ext/reflection/tests/ReflectionMethod_006.phpt +++ b/ext/reflection/tests/ReflectionMethod_006.phpt @@ -6,8 +6,16 @@ Steve Seear <stevseea@php.net> --FILE-- <?php -var_dump(new ReflectionMethod()); -var_dump(new ReflectionMethod('a', 'b', 'c')); +try { + new ReflectionMethod(); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + new ReflectionMethod('a', 'b', 'c'); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} class C { public function f() {} @@ -35,21 +43,8 @@ var_dump($rm->getName(1)); ?> --EXPECTF-- -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line %d -object(ReflectionMethod)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line %d -object(ReflectionMethod)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt b/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt index 2a2f02ffe0..243c59504b 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_basic.phpt @@ -85,7 +85,7 @@ var_dump($methodInfo->isConstructor()); ?> --EXPECTF-- -Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OldCtor has a deprecated constructor in %s on line %d New-style constructor: bool(true) diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt index 70528255e7..f7beea67a6 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_error1.phpt @@ -65,37 +65,37 @@ try { ?> --EXPECTF-- Wrong type of argument (bool): -exception 'ReflectionException' with message 'Invalid method name 1' in %s +ReflectionException: Invalid method name 1 in %s Stack trace: #0 %s ReflectionMethod->__construct('1') #1 {main} Wrong type of argument (int): -exception 'ReflectionException' with message 'Invalid method name 3' in %s +ReflectionException: Invalid method name 3 in %s Stack trace: #0 %s ReflectionMethod->__construct('3') #1 {main} Wrong type of argument (bool, string): -exception 'ReflectionException' with message 'The parameter class is expected to be either a string or an object' in %s +ReflectionException: The parameter class is expected to be either a string or an object in %s Stack trace: #0 %s ReflectionMethod->__construct(true, 'foo') #1 {main} Wrong type of argument (string, bool): -exception 'ReflectionException' with message 'Method TestClass::1() does not exist' in %s +ReflectionException: Method TestClass::1() does not exist in %s Stack trace: #0 %s ReflectionMethod->__construct('TestClass', '1') #1 {main} No method given: -exception 'ReflectionException' with message 'Invalid method name TestClass' in %s +ReflectionException: Invalid method name TestClass in %s Stack trace: #0 %s ReflectionMethod->__construct('TestClass') #1 {main} Class and Method in same string, bad method name: -exception 'ReflectionException' with message 'Method TestClass::foop::dedoop() does not exist' in %s +ReflectionException: Method TestClass::foop::dedoop() does not exist in %s Stack trace: #0 %s ReflectionMethod->__construct('TestClass::foop...') #1 {main} Class and Method in same string, bad class name: -exception 'ReflectionException' with message 'Class TestCla does not exist' in %s +ReflectionException: Class TestCla does not exist in %s Stack trace: #0 %s ReflectionMethod->__construct('TestCla::foo') #1 {main} diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt index 1c2d3a138f..98125cba65 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt @@ -16,22 +16,47 @@ class TestClass try { echo "Too few arguments:\n"; $methodInfo = new ReflectionMethod(); -} catch (Exception $e) { - print $e->__toString(); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } try { echo "\nToo many arguments:\n"; $methodInfo = new ReflectionMethod("TestClass", "foo", true); -} catch (Exception $e) { - print $e->__toString(); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + +try { + //invalid class + $methodInfo = new ReflectionMethod("InvalidClassName", "foo"); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + +try { + //invalid 1st param + $methodInfo = new ReflectionMethod([], "foo"); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try{ + //invalid 2nd param + $methodInfo = new ReflectionMethod("TestClass", []); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } ?> --EXPECTF-- Too few arguments: - -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12 +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given Too many arguments: +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given +Ok - Class InvalidClassName does not exist +Ok - The parameter class is expected to be either a string or an object +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18 diff --git a/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt b/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt index b04fb6c9fc..e79092421d 100644 --- a/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt @@ -2,7 +2,6 @@ ReflectionMethod::getDocComment() --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php /** diff --git a/ext/reflection/tests/ReflectionMethod_getDocComment_property_list.phpt b/ext/reflection/tests/ReflectionMethod_getDocComment_property_list.phpt new file mode 100644 index 0000000000..4719571124 --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_getDocComment_property_list.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionMethod::getDocComment() +--INI-- +opcache.save_comments=1 +--FILE-- +<?php + +class X { + /** + * doc 1 + */ + // Some comment + public + $x = "x", + $y = 'y', + /** doc 2 */ + $z = 'z' + ; +} + +$reflection = new ReflectionProperty('\X', 'x'); +echo 'X::x', PHP_EOL; +var_dump($reflection->getDocComment()); + +$reflection = new ReflectionProperty('\X', 'y'); +echo 'X::y', PHP_EOL; +var_dump($reflection->getDocComment()); + +$reflection = new ReflectionProperty('\X', 'z'); +echo 'X::z', PHP_EOL; +var_dump($reflection->getDocComment()); +?> +--EXPECTF-- +X::x +string(24) "/** + * doc 1 + */" +X::y +bool(false) +X::z +string(12) "/** doc 2 */" diff --git a/ext/reflection/tests/ReflectionMethod_getPrototype_basic.phpt b/ext/reflection/tests/ReflectionMethod_getPrototype_basic.phpt new file mode 100644 index 0000000000..c57a529d7b --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_getPrototype_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +public ReflectionMethod ReflectionMethod::getPrototype ( void ); +--CREDITS-- +marcosptf - <marcosptf@yahoo.com.br> +--FILE-- +<?php +class Hello { + public function sayHelloTo($name) { + return 'Hello ' . $name; + } +} + +class HelloWorld extends Hello { + public function sayHelloTo($name) { + return 'Hello world: ' . $name; + } +} + +$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo'); +var_dump($reflectionMethod->getPrototype()); + +?> +--EXPECT-- +object(ReflectionMethod)#2 (2) { + ["name"]=> + string(10) "sayHelloTo" + ["class"]=> + string(5) "Hello" +} diff --git a/ext/reflection/tests/ReflectionMethod_invokeArgs_error2.phpt b/ext/reflection/tests/ReflectionMethod_invokeArgs_error2.phpt index 5fc7564245..8bedbea0cb 100644 --- a/ext/reflection/tests/ReflectionMethod_invokeArgs_error2.phpt +++ b/ext/reflection/tests/ReflectionMethod_invokeArgs_error2.phpt @@ -18,10 +18,10 @@ $testClassInstance = new TestClass(); try { var_dump($foo->invokeArgs($testClassInstance, true)); -} catch (Exception $e) { +} catch (Error $e) { var_dump($e->getMessage()); } ?> ---EXPECTF-- -Catchable fatal error: Argument 2 passed to ReflectionMethod::invokeArgs() must be of the type array, boolean given in %s on line %d +--EXPECT-- +string(92) "Argument 2 passed to ReflectionMethod::invokeArgs() must be of the type array, boolean given" diff --git a/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt b/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt index 5a0c36f9ee..2fb43562bb 100644 --- a/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt +++ b/ext/reflection/tests/ReflectionObject_getConstructor_basic.phpt @@ -64,7 +64,11 @@ foreach ($classes as $class) { ?> --EXPECTF-- -Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OldCtor has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; B has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; C has a deprecated constructor in %s on line %d Constructor of NewCtor: __construct Constructor of ExtendsNewCtor: __construct Constructor of OldCtor: OldCtor diff --git a/ext/reflection/tests/ReflectionObject_getName_error1.phpt b/ext/reflection/tests/ReflectionObject_getName_error1.phpt index 26c342d7f4..0d88c84398 100644 --- a/ext/reflection/tests/ReflectionObject_getName_error1.phpt +++ b/ext/reflection/tests/ReflectionObject_getName_error1.phpt @@ -5,4 +5,7 @@ ReflectionObject::getName - forbid static invocation ReflectionObject::getName(); ?> --EXPECTF-- -Fatal error: Non-static method ReflectionClass::getName() cannot be called statically in %s on line 2 +Fatal error: Uncaught Error: Non-static method ReflectionClass::getName() cannot be called statically in %s:2 +Stack trace: +#0 {main} + thrown in %s on line 2 diff --git a/ext/reflection/tests/ReflectionObject_isInstance_error.phpt b/ext/reflection/tests/ReflectionObject_isInstance_error.phpt index 692c2f8496..b0fb071e1f 100644 --- a/ext/reflection/tests/ReflectionObject_isInstance_error.phpt +++ b/ext/reflection/tests/ReflectionObject_isInstance_error.phpt @@ -25,7 +25,7 @@ NULL Warning: ReflectionClass::isInstance() expects parameter 1 to be object, integer given in %s on line 8 NULL -Warning: ReflectionClass::isInstance() expects parameter 1 to be object, double given in %s on line 9 +Warning: ReflectionClass::isInstance() expects parameter 1 to be object, float given in %s on line 9 NULL Warning: ReflectionClass::isInstance() expects parameter 1 to be object, boolean given in %s on line 10 diff --git a/ext/reflection/tests/ReflectionObject_isInstantiable_error.phpt b/ext/reflection/tests/ReflectionObject_isInstantiable_error.phpt index f993367b2d..c77c039d4d 100644 --- a/ext/reflection/tests/ReflectionObject_isInstantiable_error.phpt +++ b/ext/reflection/tests/ReflectionObject_isInstantiable_error.phpt @@ -15,6 +15,8 @@ var_dump($reflectionObject->IsInstantiable(0, null)); ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; privateCtorOld has a deprecated constructor in %s on line %d + Warning: ReflectionClass::isInstantiable() expects exactly 0 parameters, 1 given in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionObject_isInstantiable_variation.phpt b/ext/reflection/tests/ReflectionObject_isInstantiable_variation.phpt index ac7199c096..1e5be59299 100644 --- a/ext/reflection/tests/ReflectionObject_isInstantiable_variation.phpt +++ b/ext/reflection/tests/ReflectionObject_isInstantiable_variation.phpt @@ -69,6 +69,11 @@ foreach($reflectionObjects as $reflectionObject ) { } ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; publicCtorOld has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; protectedCtorOld has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; privateCtorOld has a deprecated constructor in %s on line %d Is noCtor instantiable? bool(true) Is publicCtorNew instantiable? bool(true) Is protectedCtorNew instantiable? bool(false) diff --git a/ext/reflection/tests/ReflectionObject_isSubclassOf_error.phpt b/ext/reflection/tests/ReflectionObject_isSubclassOf_error.phpt index 9387b7dcb3..11994ed705 100644 --- a/ext/reflection/tests/ReflectionObject_isSubclassOf_error.phpt +++ b/ext/reflection/tests/ReflectionObject_isSubclassOf_error.phpt @@ -17,7 +17,7 @@ NULL Warning: ReflectionClass::isSubclassOf() expects exactly 1 parameter, 2 given in %s on line 6 NULL -Fatal error: Uncaught exception 'ReflectionException' with message 'Class X does not exist' in %s:7 +Fatal error: Uncaught ReflectionException: Class X does not exist in %s:7 Stack trace: #0 %s(7): ReflectionClass->isSubclassOf('X') #1 {main} diff --git a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt index cdd00d2624..20f4c95dc7 100644 --- a/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt +++ b/ext/reflection/tests/ReflectionParameter_DefaultValueConstant_basic1.phpt @@ -5,7 +5,7 @@ ReflectionParameter::isDefaultValueConstant() && getDefaultValueConstantName() define("CONST_TEST_1", "const1"); -function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1) { +function ReflectionParameterTest($test1=array(), $test2 = CONST_TEST_1, $test3 = CASE_LOWER) { echo $test; } $reflect = new ReflectionFunction('ReflectionParameterTest'); @@ -46,6 +46,7 @@ foreach ($params as $param) { bool(false) bool(true) string(12) "CONST_TEST_1" +string(10) "CASE_LOWER" string(9) "self::bar" string(9) "Foo2::bar" string(12) "CONST_TEST_1" diff --git a/ext/reflection/tests/ReflectionParameter_export_error3.phpt b/ext/reflection/tests/ReflectionParameter_export_error3.phpt index 2937853288..4e71f55d45 100644 --- a/ext/reflection/tests/ReflectionParameter_export_error3.phpt +++ b/ext/reflection/tests/ReflectionParameter_export_error3.phpt @@ -14,7 +14,7 @@ foreach($params as $key => $value) { } --EXPECTF-- -Fatal error: Uncaught exception 'ReflectionException' with message 'The parameter specified by its name could not be found' in %s.php:%d +Fatal error: Uncaught ReflectionException: The parameter specified by its name could not be found in %s.php:%d Stack trace: #0 [internal function]: ReflectionParameter->__construct('ReflectionParam...', 'incorrect_param...') #1 %s.php(%d): ReflectionParameter::export('ReflectionParam...', 'incorrect_param...') diff --git a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt index 3118c17be8..6c154558e9 100644 --- a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt +++ b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt @@ -6,7 +6,7 @@ ReflectionParameter::__construct(): Invalid method as constructor // Invalid class name try { new ReflectionParameter (array ('A', 'b'), 0); -} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } +} catch (ReflectionException $e) { echo $e->getMessage()."\n"; } // Invalid class method try { @@ -18,14 +18,31 @@ try { new ReflectionParameter (array (new C, 'b'), 0); } catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } -echo "Done.\n"; class C { } +try { + new ReflectionParameter(array ('A', 'b')); +} +catch(TypeError $e) { + printf( "Ok - %s\n", $e->getMessage()); +} + +try { + new ReflectionParameter(0, 0); +} +catch(ReflectionException $e) { + printf( "Ok - %s\n", $e->getMessage()); +} + +echo "Done.\n"; + ?> --EXPECTF-- Class A does not exist Method C::b() does not exist Method C::b() does not exist +Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given +Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object Done. diff --git a/ext/reflection/tests/ReflectionProperty_basic2.phpt b/ext/reflection/tests/ReflectionProperty_basic2.phpt index bc42d3f828..62938df100 100644 --- a/ext/reflection/tests/ReflectionProperty_basic2.phpt +++ b/ext/reflection/tests/ReflectionProperty_basic2.phpt @@ -2,7 +2,6 @@ Test usage of ReflectionProperty methods isDefault(), getModifiers(), getDeclaringClass() and getDocComment(). --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/ReflectionProperty_error.phpt b/ext/reflection/tests/ReflectionProperty_error.phpt index 56de6e1f2e..c8a2f11ee1 100644 --- a/ext/reflection/tests/ReflectionProperty_error.phpt +++ b/ext/reflection/tests/ReflectionProperty_error.phpt @@ -7,9 +7,24 @@ class C { public static $p; } -var_dump(new ReflectionProperty()); -var_dump(new ReflectionProperty('C::p')); -var_dump(new ReflectionProperty('C', 'p', 'x')); +try { + new ReflectionProperty(); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + new ReflectionProperty('C::p'); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try { + new ReflectionProperty('C', 'p', 'x'); +} catch (TypeError $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + $rp = new ReflectionProperty('C', 'p'); var_dump($rp->getName(1)); var_dump($rp->isPrivate(1)); @@ -21,29 +36,9 @@ var_dump($rp->isDefault(1)); ?> --EXPECTF-- -Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given in %s on line %d -object(ReflectionProperty)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 1 given in %s on line %d -object(ReflectionProperty)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 3 given in %s on line %d -object(ReflectionProperty)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} +Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 0 given +Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 1 given +Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 3 given Warning: ReflectionProperty::getName() expects exactly 0 parameters, 1 given in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt b/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt index f94ee8ca4c..8491f32597 100644 --- a/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt +++ b/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt @@ -2,7 +2,6 @@ Test ReflectionProperty::getDocComment() usage. --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/ReflectionProperty_getValue_error.phpt b/ext/reflection/tests/ReflectionProperty_getValue_error.phpt index c2152e9f87..62009d8bb9 100644 --- a/ext/reflection/tests/ReflectionProperty_getValue_error.phpt +++ b/ext/reflection/tests/ReflectionProperty_getValue_error.phpt @@ -78,4 +78,6 @@ Protected property: Cannot access non-public member TestClass::prot Instance without property: + +Notice: Undefined property: AnotherClass::$pub2 in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionType_001.phpt b/ext/reflection/tests/ReflectionType_001.phpt new file mode 100644 index 0000000000..f764cf1519 --- /dev/null +++ b/ext/reflection/tests/ReflectionType_001.phpt @@ -0,0 +1,185 @@ +--TEST-- +ReflectionParameter::get/hasType and ReflectionType tests +--FILE-- +<?php +function foo(stdClass $a, array $b, callable $c, stdClass $d = null, $e = null, string $f, bool $g, int $h, float $i, NotExisting $j) { } + +function bar(): stdClass { return new stdClass; } + +class c extends stdClass { + function bar(self $x): int { return 1; } + function pbar(parent $x): int { return 1; } + function factory(): self { return new c; } + function pfactory(): parent { return new stdClass; } +} + +$closure = function (Test $a): Test { return $a; }; + +echo "*** functions\n"; + +foreach ([ + new ReflectionFunction('foo'), + new ReflectionFunction($closure), +] as $idx => $rf) { + foreach ($rf->getParameters() as $idx2 => $rp) { + echo "** Function $idx - Parameter $idx2\n"; + var_dump($rp->hasType()); + $ra = $rp->getType(); + if ($ra) { + var_dump($ra->allowsNull()); + var_dump($ra->isBuiltin()); + var_dump((string)$ra); + } + } +} + +echo "\n*** methods\n"; + +foreach ([ + new ReflectionMethod('SplObserver', 'update'), + new ReflectionMethod('c', 'bar'), + new ReflectionMethod('c', 'pbar'), + new ReflectionMethod($closure, '__invoke'), +] as $idx => $rm) { + foreach ($rm->getParameters() as $idx2 => $rp) { + echo "** Method $idx - parameter $idx2\n"; + var_dump($rp->hasType()); + $ra = $rp->getType(); + if ($ra) { + var_dump($ra->allowsNull()); + var_dump($ra->isBuiltin()); + var_dump((string)$ra); + } + } +} + +echo "\n*** return types\n"; + +foreach ([ + new ReflectionMethod('SplObserver', 'update'), + new ReflectionFunction('bar'), + new ReflectionMethod('c', 'bar'), + new ReflectionMethod('c', 'factory'), + new ReflectionMethod('c', 'pfactory'), + new ReflectionFunction($closure), + new ReflectionMethod($closure, '__invoke'), +] as $idx => $rf) { + echo "** Function/method return type $idx\n"; + var_dump($rf->hasReturnType()); + $ra = $rf->getReturnType(); + if ($ra) { + var_dump($ra->allowsNull()); + var_dump($ra->isBuiltin()); + var_dump((string)$ra); + } +} +--EXPECT-- +*** functions +** Function 0 - Parameter 0 +bool(true) +bool(false) +bool(false) +string(8) "stdClass" +** Function 0 - Parameter 1 +bool(true) +bool(false) +bool(true) +string(5) "array" +** Function 0 - Parameter 2 +bool(true) +bool(false) +bool(true) +string(8) "callable" +** Function 0 - Parameter 3 +bool(true) +bool(true) +bool(false) +string(8) "stdClass" +** Function 0 - Parameter 4 +bool(false) +** Function 0 - Parameter 5 +bool(true) +bool(false) +bool(true) +string(6) "string" +** Function 0 - Parameter 6 +bool(true) +bool(false) +bool(true) +string(4) "bool" +** Function 0 - Parameter 7 +bool(true) +bool(false) +bool(true) +string(3) "int" +** Function 0 - Parameter 8 +bool(true) +bool(false) +bool(true) +string(5) "float" +** Function 0 - Parameter 9 +bool(true) +bool(false) +bool(false) +string(11) "NotExisting" +** Function 1 - Parameter 0 +bool(true) +bool(false) +bool(false) +string(4) "Test" + +*** methods +** Method 0 - parameter 0 +bool(true) +bool(false) +bool(false) +string(10) "SplSubject" +** Method 1 - parameter 0 +bool(true) +bool(false) +bool(false) +string(4) "self" +** Method 2 - parameter 0 +bool(true) +bool(false) +bool(false) +string(6) "parent" +** Method 3 - parameter 0 +bool(true) +bool(false) +bool(false) +string(4) "Test" + +*** return types +** Function/method return type 0 +bool(false) +** Function/method return type 1 +bool(true) +bool(false) +bool(false) +string(8) "stdClass" +** Function/method return type 2 +bool(true) +bool(false) +bool(true) +string(3) "int" +** Function/method return type 3 +bool(true) +bool(false) +bool(false) +string(4) "self" +** Function/method return type 4 +bool(true) +bool(false) +bool(false) +string(6) "parent" +** Function/method return type 5 +bool(true) +bool(false) +bool(false) +string(4) "Test" +** Function/method return type 6 +bool(true) +bool(false) +bool(false) +string(4) "Test" diff --git a/ext/reflection/tests/ReflectionType_002.phpt b/ext/reflection/tests/ReflectionType_002.phpt new file mode 100644 index 0000000000..8313862ec5 --- /dev/null +++ b/ext/reflection/tests/ReflectionType_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionType leak +--FILE-- +<?php + +$closure = function(Test $x): Test2 { return new Test2($x); }; +$rm = new ReflectionMethod($closure, '__invoke'); +$rp = $rm->getParameters()[0]; +$rt = $rp->getType(); +$rrt = $rm->getReturnType(); +unset($rm, $rp); +var_dump((string) $rt, (string) $rrt); + +--EXPECT-- +string(4) "Test" +string(5) "Test2" + diff --git a/ext/reflection/tests/bug29986.phpt b/ext/reflection/tests/bug29986.phpt index d30b3a6f88..4c4d629f39 100644 --- a/ext/reflection/tests/bug29986.phpt +++ b/ext/reflection/tests/bug29986.phpt @@ -24,7 +24,7 @@ Class [ <user> class just_constants ] { Constant [ null NULL_CONSTANT ] { } Constant [ string STRING_CONSTANT ] { This is a string } Constant [ integer INTEGER_CONSTANT ] { 1000 } - Constant [ double FLOAT_CONSTANT ] { 3.14159265 } + Constant [ float FLOAT_CONSTANT ] { 3.14159265 } } - Static properties [0] { diff --git a/ext/reflection/tests/bug30148.phpt b/ext/reflection/tests/bug30148.phpt index aa5841ee5b..27c31ca6ae 100644 --- a/ext/reflection/tests/bug30148.phpt +++ b/ext/reflection/tests/bug30148.phpt @@ -26,7 +26,8 @@ var_dump($d->isConstructor()); var_dump($e->isConstructor()); ?> ===DONE=== ---EXPECT-- +--EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Root has a deprecated constructor in %s on line %d bool(true) bool(false) bool(true) diff --git a/ext/reflection/tests/bug36308.phpt b/ext/reflection/tests/bug36308.phpt index f923ee31ab..17d3cf1026 100644 --- a/ext/reflection/tests/bug36308.phpt +++ b/ext/reflection/tests/bug36308.phpt @@ -2,7 +2,6 @@ Reflection Bug #36308 (ReflectionProperty::getDocComment() does not reflect extended class commentary) --INI-- opcache.save_comments=1 -opcache.load_comments=1 --FILE-- <?php class Base { diff --git a/ext/reflection/tests/bug36434.phpt b/ext/reflection/tests/bug36434.phpt index 218055d546..9598a40b7b 100644 --- a/ext/reflection/tests/bug36434.phpt +++ b/ext/reflection/tests/bug36434.phpt @@ -4,16 +4,16 @@ Reflection Bug #36434 (Properties from parent class fail to indetify their true <?php class ancester { -public $ancester = 0; - function ancester() + public $ancester = 0; + function __construct() { return $this->ancester; } } class foo extends ancester { -public $bar = "1"; - function foo() + public $bar = "1"; + function __construct() { return $this->bar; } diff --git a/ext/reflection/tests/bug38942.phpt b/ext/reflection/tests/bug38942.phpt index 817190c997..59666607cb 100644 --- a/ext/reflection/tests/bug38942.phpt +++ b/ext/reflection/tests/bug38942.phpt @@ -11,6 +11,7 @@ class bar extends foo { ReflectionClass::export("bar"); ?> --EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; foo has a deprecated constructor in %s on line %d Class [ <user> class bar extends foo ] { @@ %sbug38942.php 6-7 diff --git a/ext/reflection/tests/bug40431.phpt b/ext/reflection/tests/bug40431.phpt index 863df7a78f..0c96e70faf 100644 --- a/ext/reflection/tests/bug40431.phpt +++ b/ext/reflection/tests/bug40431.phpt @@ -80,7 +80,7 @@ echo "Done\n"; === 1st test === array(1) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "value" ["class"]=> @@ -94,7 +94,7 @@ bool(false) === 2nd test === array(1) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "value" ["class"]=> @@ -108,7 +108,7 @@ bool(false) === 3rd test === array(1) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "value" ["class"]=> @@ -122,7 +122,7 @@ bool(false) === 4th test === array(1) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(5) "value" ["class"]=> diff --git a/ext/reflection/tests/bug46064_2.phpt b/ext/reflection/tests/bug46064_2.phpt index da14148a7a..0b74708dff 100644 --- a/ext/reflection/tests/bug46064_2.phpt +++ b/ext/reflection/tests/bug46064_2.phpt @@ -57,14 +57,14 @@ bool(true) bool(false) array(2) { [0]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(1) "b" ["class"]=> string(4) "test" } [1]=> - &object(ReflectionProperty)#%d (2) { + object(ReflectionProperty)#%d (2) { ["name"]=> string(1) "a" ["class"]=> diff --git a/ext/reflection/tests/bug46103.phpt b/ext/reflection/tests/bug46103.phpt new file mode 100644 index 0000000000..978a9c2c46 --- /dev/null +++ b/ext/reflection/tests/bug46103.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #46103: ReflectionObject memory leak +--FILE-- +<?php + +$obj = new stdClass; +$obj->r = new ReflectionObject($obj); +var_dump($obj); + +?> +--EXPECT-- +object(stdClass)#1 (1) { + ["r"]=> + object(ReflectionObject)#2 (1) { + ["name"]=> + string(8) "stdClass" + } +} diff --git a/ext/reflection/tests/bug47254.phpt b/ext/reflection/tests/bug47254.phpt index 83593a4ff2..38cdcd62b4 100644 --- a/ext/reflection/tests/bug47254.phpt +++ b/ext/reflection/tests/bug47254.phpt @@ -23,7 +23,10 @@ $m = $R->getMethods(); print_r($m); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d + +Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; B has a deprecated constructor in %s on line %d Array ( [0] => ReflectionMethod Object diff --git a/ext/reflection/tests/bug64007.phpt b/ext/reflection/tests/bug64007.phpt index ae3ec50328..a25beb6360 100644 --- a/ext/reflection/tests/bug64007.phpt +++ b/ext/reflection/tests/bug64007.phpt @@ -16,4 +16,8 @@ var_dump($generator); --EXPECTF-- string(%d) "Class Generator is an internal class marked as final that cannot be instantiated without invoking its constructor" -Catchable fatal error: The "Generator" class is reserved for internal use and cannot be manually instantiated in %sbug64007.php on line %d +Fatal error: Uncaught Error: The "Generator" class is reserved for internal use and cannot be manually instantiated in %sbug64007.php:%d +Stack trace: +#0 %s(%d): ReflectionClass->newInstance() +#1 {main} + thrown in %sbug64007.php on line %d diff --git a/ext/reflection/tests/bug64936.phpt b/ext/reflection/tests/bug64936.phpt index 363a17f509..a4a66d4f48 100644 --- a/ext/reflection/tests/bug64936.phpt +++ b/ext/reflection/tests/bug64936.phpt @@ -2,7 +2,6 @@ ReflectionMethod::getDocComment() uses left over doc comment from previous scanner run --INI-- opcache.save_comments=1 -opcache.load_comments=1 --SKIPIF-- <?php if (!extension_loaded('reflection') || !extension_loaded('tokenizer')) print 'skip missing reflection of tokernizer extension'; diff --git a/ext/reflection/tests/bug70674.phpt b/ext/reflection/tests/bug70674.phpt new file mode 100644 index 0000000000..82cfc53f1e --- /dev/null +++ b/ext/reflection/tests/bug70674.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #70674 (ReflectionFunction::getClosure() leaks memory when used for internal functions) +--FILE-- +<?php +var_dump(((new ReflectionFunction("strlen"))->getClosure())("hello")); +?> +--EXPECT-- +int(5) diff --git a/ext/reflection/tests/bug70982.phpt b/ext/reflection/tests/bug70982.phpt new file mode 100644 index 0000000000..d530846f64 --- /dev/null +++ b/ext/reflection/tests/bug70982.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #70982 (setStaticPropertyValue behaviors inconsistently with 5.6) +--FILE-- +<?php +class Foo { + static $abc; + function __construct() + { + var_dump(self::$abc); + } +} + +class Bar extends Foo { + +} + +$rf = new ReflectionClass('Bar'); +$rf->setStaticPropertyValue('abc', 'hi'); +$foo = $rf->newInstance(); +?> +--EXPECT-- +string(2) "hi" diff --git a/ext/reflection/tests/bug71018.phpt b/ext/reflection/tests/bug71018.phpt new file mode 100644 index 0000000000..00baa31d3c --- /dev/null +++ b/ext/reflection/tests/bug71018.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #71018 (ReflectionProperty::setValue() behavior changed) +--FILE-- +<?php +class T1 { + public static $data; + + public static function getDataBySelf() + { + return self::$data; + } + + public static function getDataByStatic() + { + return static::$data; + } +} + +class T2 extends T1 {} + +$Prop1 = new ReflectionProperty(T1::class, 'data'); +$Prop2 = new ReflectionProperty(T2::class, 'data'); + +// #1 +// prints: hello, hello in PHP5, but world, hello in PHP7 - not OK +$Prop1->setValue(\T1::class, "world"); +$Prop2->setValue(\T2::class, 'hello'); +var_dump("T2::self = " . T2::getDataBySelf()); +var_dump("T2::static = " . T2::getDataByStatic()); + +// #2 +// prints: hello, hello in both PHP5 and PHP7 - OK +T1::$data = "world"; +T2::$data = 'hello'; + +var_dump("T2::self = " . T2::getDataBySelf()); +var_dump("T2::static = " . T2::getDataByStatic()); +?> +--EXPECT-- +string(16) "T2::self = hello" +string(18) "T2::static = hello" +string(16) "T2::self = hello" +string(18) "T2::static = hello" diff --git a/ext/reflection/tests/bug71767.phpt b/ext/reflection/tests/bug71767.phpt new file mode 100644 index 0000000000..8c4059abf4 --- /dev/null +++ b/ext/reflection/tests/bug71767.phpt @@ -0,0 +1,44 @@ +--TEST-- +Bug #71767 (ReflectionMethod::getDocComment returns the wrong comment) +--FILE-- +<?php + +/** Correct docblock */ +function foo( + /** wrong docblock */ + $arg +) { +} + +class Foo { + /** Correct docblock */ + public function bar( + /** wrong docblock */ + $arg + ) { + + } +} + +/** Correct docblock */ +$func = function( + /** wrong docblock */ + $arg +) { +}; + +$reflectionFunction = new ReflectionFunction('foo'); +$reflectionClass = new ReflectionClass(Foo::class); +$reflectionClosure = new ReflectionFunction($func); + +echo $reflectionFunction->getDocComment() . PHP_EOL; +echo $reflectionClass->getMethod('bar')->getDocComment() . PHP_EOL; +echo $reflectionClosure->getDocComment() . PHP_EOL; + +echo "Done\n"; +?> +--EXPECTF-- +/** Correct docblock */ +/** Correct docblock */ +/** Correct docblock */ +Done diff --git a/ext/reflection/tests/bug72174.phpt b/ext/reflection/tests/bug72174.phpt new file mode 100644 index 0000000000..94416d6153 --- /dev/null +++ b/ext/reflection/tests/bug72174.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #72174: ReflectionProperty#getValue() causes __isset call +--FILE-- +<?php + +class Foo +{ + private $bar; + + public function __construct() + { + unset($this->bar); + } + + public function __isset($name) + { + var_dump(__METHOD__); + return true; + } + + public function __get($name) + { + var_dump(__METHOD__); + return $name; + } +} + +$instance = new Foo(); +$reflectionBar = (new ReflectionProperty(Foo::class, 'bar')); +$reflectionBar->setAccessible(true); +var_dump($reflectionBar->getValue($instance)); + +?> +--EXPECT-- +string(10) "Foo::__get" +string(3) "bar" diff --git a/ext/reflection/tests/bug72846.phpt b/ext/reflection/tests/bug72846.phpt new file mode 100644 index 0000000000..ab8b6cac79 --- /dev/null +++ b/ext/reflection/tests/bug72846.phpt @@ -0,0 +1,48 @@ +--TEST-- +Bug #72846 (getConstant for a array constant with constant values returns NULL/NFC/UKNOWN) +--FILE-- +<?php + +namespace Some { + + abstract class A + { + const ONE = '1'; + const TWO = '2'; + + const CONST_NUMBERS = [ + self::ONE, + self::TWO, + ]; + + const NUMBERS = [ + '1', + '2', + ]; + } + + class B extends A + { + } + + $ref = new \ReflectionClass('Some\B'); + + var_dump($ref->getConstant('ONE')); + var_dump($ref->getConstant('CONST_NUMBERS')); + var_dump($ref->getConstant('NUMBERS')); +} +?> +--EXPECT-- +string(1) "1" +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} diff --git a/ext/reflection/tests/parameters_002.phpt b/ext/reflection/tests/parameters_002.phpt index a86191042f..ae924323a0 100644 --- a/ext/reflection/tests/parameters_002.phpt +++ b/ext/reflection/tests/parameters_002.phpt @@ -3,13 +3,15 @@ ReflectionParameter::getClass(), getDeclaringClass(), getDeclaringFunction() --FILE-- <?php -function test($nix, Array $ar, &$ref, stdClass $std, NonExistingClass $na, stdClass &$opt = NULL, $def = "FooBar") +function test($nix, Array $ar, &$ref, stdClass $std, + NonExistingClass $na, stdClass &$opt = NULL, $def = "FooBar") { } class test { - function test($nix, Array $ar, &$ref, stdClass $std, NonExistingClass $na, stdClass $opt = NULL, $def = "FooBar") + function method($nix, Array $ar, &$ref, stdClass $std, + NonExistingClass $na, stdClass $opt = NULL, $def = "FooBar") { } } @@ -17,7 +19,8 @@ class test function check_params_decl_func($r, $f) { $c = $r->$f(); - echo $f . ': ' . ($c ? ($c instanceof ReflectionMethod ? $c->class . '::' : '') . $c->name : 'NULL') . "()\n"; + $sep = $c instanceof ReflectionMethod ? $c->class . '::' : ''; + echo $f . ': ' . ($c ? $sep . $c->name : 'NULL') . "()\n"; } function check_params_decl_class($r, $f) @@ -66,7 +69,7 @@ function check_params($r) check_params(new ReflectionFunction('test')); -check_params(new ReflectionMethod('test::test')); +check_params(new ReflectionMethod('test::method')); ?> ===DONE=== @@ -138,7 +141,7 @@ allowsNull: bool(true) isOptional: bool(true) isDefaultValueAvailable: bool(true) getDefaultValue: string(6) "FooBar" -#####test::test()##### +#####test::method()##### ===0=== getName: string(3) "nix" isPassedByReference: bool(false) diff --git a/ext/reflection/tests/reflectionclass_for_traits.phpt b/ext/reflection/tests/reflectionclass_for_traits.phpt new file mode 100644 index 0000000000..526310a8b9 --- /dev/null +++ b/ext/reflection/tests/reflectionclass_for_traits.phpt @@ -0,0 +1,20 @@ +--TEST-- +Tests some parts of ReflectionClass behavior for traits +--FILE-- +<?php + +trait T {} + +$r = new ReflectionClass('T'); +var_dump(Reflection::getModifierNames($r->getModifiers())); +var_dump($r->isAbstract()); +var_dump($r->isInstantiable()); +var_dump($r->isCloneable()); + +?> +--EXPECT-- +array(0) { +} +bool(false) +bool(false) +bool(false) diff --git a/ext/reflection/tests/traits004.phpt b/ext/reflection/tests/traits004.phpt index c9367c1f48..ca0314d0df 100644 --- a/ext/reflection/tests/traits004.phpt +++ b/ext/reflection/tests/traits004.phpt @@ -30,7 +30,7 @@ array(1) { } array(1) { ["T1"]=> - &object(ReflectionClass)#1 (1) { + object(ReflectionClass)#1 (1) { ["name"]=> string(2) "T1" } @@ -45,12 +45,12 @@ array(2) { } array(2) { ["T1"]=> - &object(ReflectionClass)#2 (1) { + object(ReflectionClass)#2 (1) { ["name"]=> string(2) "T1" } ["T2"]=> - &object(ReflectionClass)#3 (1) { + object(ReflectionClass)#3 (1) { ["name"]=> string(2) "T2" } |
