summaryrefslogtreecommitdiff
path: root/ext/reflection/php_reflection.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r--ext/reflection/php_reflection.c150
1 files changed, 59 insertions, 91 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index e7df9bfa61..4e556b3cbc 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -246,9 +244,9 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
}
/* }}} */
-static HashTable *reflection_get_gc(zval *obj, zval **gc_data, int *gc_data_count) /* {{{ */
+static HashTable *reflection_get_gc(zend_object *obj, zval **gc_data, int *gc_data_count) /* {{{ */
{
- reflection_object *intern = Z_REFLECTION_P(obj);
+ reflection_object *intern = reflection_object_from_obj(obj);
*gc_data = &intern->obj;
*gc_data_count = 1;
return zend_std_get_properties(obj);
@@ -445,7 +443,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
smart_str_append_printf(str, "%s }\n", indent);
if (obj && Z_TYPE_P(obj) == IS_OBJECT) {
- HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj);
+ HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(Z_OBJ_P(obj));
zend_string *prop_name;
smart_str prop_str = {0};
@@ -512,7 +510,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
/* {{{ _const_string */
static void _const_string(smart_str *str, char *name, zval *value, char *indent)
{
- char *type = zend_zval_type_name(value);
+ const char *type = zend_zval_type_name(value);
if (Z_TYPE_P(value) == IS_ARRAY) {
smart_str_append_printf(str, "%s Constant [ %s %s ] { Array }\n",
@@ -534,7 +532,7 @@ static void _const_string(smart_str *str, char *name, zval *value, char *indent)
static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char *indent)
{
char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value));
- char *type;
+ const char *type;
zval_update_constant_ex(&c->value, c->ce);
type = zend_zval_type_name(&c->value);
@@ -582,17 +580,10 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_
} else {
smart_str_append_printf(str, "<required> ");
}
- if (ZEND_TYPE_IS_CLASS(arg_info->type)) {
- smart_str_append_printf(str, "%s ",
- ZSTR_VAL(ZEND_TYPE_NAME(arg_info->type)));
- if (ZEND_TYPE_ALLOW_NULL(arg_info->type)) {
- smart_str_append_printf(str, "or NULL ");
- }
- } else if (ZEND_TYPE_IS_CODE(arg_info->type)) {
- smart_str_append_printf(str, "%s ", zend_get_type_by_const(ZEND_TYPE_CODE(arg_info->type)));
- if (ZEND_TYPE_ALLOW_NULL(arg_info->type)) {
- smart_str_append_printf(str, "or NULL ");
- }
+ if (ZEND_TYPE_IS_SET(arg_info->type)) {
+ zend_string *type_str = zend_type_to_string(arg_info->type);
+ smart_str_append_printf(str, "%s ", ZSTR_VAL(type_str));
+ zend_string_release(type_str);
}
if (arg_info->pass_by_reference) {
smart_str_appendc(str, '&');
@@ -802,17 +793,10 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
smart_str_free(&param_indent);
if (fptr->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
smart_str_append_printf(str, " %s- Return [ ", indent);
- if (ZEND_TYPE_IS_CLASS(fptr->common.arg_info[-1].type)) {
- smart_str_append_printf(str, "%s ",
- ZSTR_VAL(ZEND_TYPE_NAME(fptr->common.arg_info[-1].type)));
- if (ZEND_TYPE_ALLOW_NULL(fptr->common.arg_info[-1].type)) {
- smart_str_appends(str, "or NULL ");
- }
- } else if (ZEND_TYPE_IS_CODE(fptr->common.arg_info[-1].type)) {
- smart_str_append_printf(str, "%s ", zend_get_type_by_const(ZEND_TYPE_CODE(fptr->common.arg_info[-1].type)));
- if (ZEND_TYPE_ALLOW_NULL(fptr->common.arg_info[-1].type)) {
- smart_str_appends(str, "or NULL ");
- }
+ if (ZEND_TYPE_IS_SET(fptr->common.arg_info[-1].type)) {
+ zend_string *type_str = zend_type_to_string(fptr->common.arg_info[-1].type);
+ smart_str_append_printf(str, "%s ", ZSTR_VAL(type_str));
+ zend_string_release(type_str);
}
smart_str_appends(str, "]\n");
}
@@ -1808,7 +1792,7 @@ ZEND_METHOD(reflection_function, invoke)
if (!Z_ISUNDEF(intern->obj)) {
Z_OBJ_HT(intern->obj)->get_closure(
- &intern->obj, &fcc.called_scope, &fcc.function_handler, &fcc.object);
+ Z_OBJ(intern->obj), &fcc.called_scope, &fcc.function_handler, &fcc.object, 0);
}
result = zend_call_function(&fci, &fcc);
@@ -1871,7 +1855,7 @@ ZEND_METHOD(reflection_function, invokeArgs)
if (!Z_ISUNDEF(intern->obj)) {
Z_OBJ_HT(intern->obj)->get_closure(
- &intern->obj, &fcc.called_scope, &fcc.function_handler, &fcc.object);
+ Z_OBJ(intern->obj), &fcc.called_scope, &fcc.function_handler, &fcc.object, 0);
}
result = zend_call_function(&fci, &fcc);
@@ -2386,9 +2370,7 @@ ZEND_METHOD(reflection_parameter, __construct)
failure:
if (fptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
- if (fptr->type != ZEND_OVERLOADED_FUNCTION) {
- zend_string_release_ex(fptr->common.function_name, 0);
- }
+ zend_string_release_ex(fptr->common.function_name, 0);
zend_free_trampoline(fptr);
}
if (is_closure) {
@@ -2567,13 +2549,15 @@ ZEND_METHOD(reflection_parameter, isArray)
{
reflection_object *intern;
parameter_reference *param;
+ zend_type type;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(ZEND_TYPE_CODE(param->arg_info->type) == IS_ARRAY);
+ type = ZEND_TYPE_WITHOUT_NULL(param->arg_info->type);
+ RETVAL_BOOL(ZEND_TYPE_MASK(type) == MAY_BE_ARRAY);
}
/* }}} */
@@ -2583,13 +2567,15 @@ ZEND_METHOD(reflection_parameter, isCallable)
{
reflection_object *intern;
parameter_reference *param;
+ zend_type type;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(ZEND_TYPE_CODE(param->arg_info->type) == IS_CALLABLE);
+ type = ZEND_TYPE_WITHOUT_NULL(param->arg_info->type);
+ RETVAL_BOOL(ZEND_TYPE_MASK(type) == MAY_BE_CALLABLE);
}
/* }}} */
@@ -2605,7 +2591,8 @@ ZEND_METHOD(reflection_parameter, allowsNull)
}
GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(ZEND_TYPE_ALLOW_NULL(param->arg_info->type));
+ RETVAL_BOOL(!ZEND_TYPE_IS_SET(param->arg_info->type)
+ || ZEND_TYPE_ALLOW_NULL(param->arg_info->type));
}
/* }}} */
@@ -2819,9 +2806,9 @@ ZEND_METHOD(reflection_type, allowsNull)
}
/* }}} */
-/* {{{ proto public bool ReflectionType::isBuiltin()
- Returns whether parameter is a builtin type */
-ZEND_METHOD(reflection_type, isBuiltin)
+/* {{{ proto public string ReflectionType::__toString()
+ Return the text of the type hint */
+ZEND_METHOD(reflection_type, __toString)
{
reflection_object *intern;
type_reference *param;
@@ -2831,26 +2818,13 @@ ZEND_METHOD(reflection_type, isBuiltin)
}
GET_REFLECTION_OBJECT_PTR(param);
- RETVAL_BOOL(ZEND_TYPE_IS_CODE(param->type));
-}
-/* }}} */
-
-/* {{{ reflection_type_name */
-static zend_string *reflection_type_name(type_reference *param) {
- if (ZEND_TYPE_IS_NAME(param->type)) {
- return zend_string_copy(ZEND_TYPE_NAME(param->type));
- } else if (ZEND_TYPE_IS_CE(param->type)) {
- return zend_string_copy(ZEND_TYPE_CE(param->type)->name);
- } else {
- char *name = zend_get_type_by_const(ZEND_TYPE_CODE(param->type));
- return zend_string_init(name, strlen(name), 0);
- }
+ RETURN_STR(zend_type_to_string(ZEND_TYPE_WITHOUT_NULL(param->type)));
}
/* }}} */
-/* {{{ proto public string ReflectionType::__toString()
- Return the text of the type hint */
-ZEND_METHOD(reflection_type, __toString)
+/* {{{ proto public string ReflectionNamedType::getName()
+ Return the name of the type */
+ZEND_METHOD(reflection_named_type, getName)
{
reflection_object *intern;
type_reference *param;
@@ -2860,13 +2834,13 @@ ZEND_METHOD(reflection_type, __toString)
}
GET_REFLECTION_OBJECT_PTR(param);
- RETURN_STR(reflection_type_name(param));
+ RETURN_STR(zend_type_to_string(ZEND_TYPE_WITHOUT_NULL(param->type)));
}
/* }}} */
-/* {{{ proto public string ReflectionNamedType::getName()
- Return the text of the type hint */
-ZEND_METHOD(reflection_named_type, getName)
+/* {{{ proto public bool ReflectionNamedType::isBuiltin()
+ Returns whether type is a builtin type */
+ZEND_METHOD(reflection_named_type, isBuiltin)
{
reflection_object *intern;
type_reference *param;
@@ -2876,7 +2850,7 @@ ZEND_METHOD(reflection_named_type, getName)
}
GET_REFLECTION_OBJECT_PTR(param);
- RETURN_STR(reflection_type_name(param));
+ RETVAL_BOOL(ZEND_TYPE_IS_MASK(param->type));
}
/* }}} */
@@ -3154,7 +3128,7 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic)
}
/* }}} */
-/* {{{ proto public mixed ReflectionMethod::invoke(mixed object, mixed* args)
+/* {{{ proto public mixed ReflectionMethod::invoke(mixed object, [mixed* args])
Invokes the method. */
ZEND_METHOD(reflection_method, invoke)
{
@@ -3727,7 +3701,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
} else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
}
- if (!prop || (prop_info->type && Z_ISUNDEF_P(prop))) {
+ if (!prop || (ZEND_TYPE_IS_SET(prop_info->type) && Z_ISUNDEF_P(prop))) {
continue;
}
@@ -3839,7 +3813,7 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue)
}
}
- if (prop_info->type && !zend_verify_property_type(prop_info, value, 0)) {
+ if (ZEND_TYPE_IS_SET(prop_info->type) && !zend_verify_property_type(prop_info, value, 0)) {
return;
}
@@ -4156,7 +4130,6 @@ ZEND_METHOD(reflection_class, hasProperty)
zend_property_info *property_info;
zend_class_entry *ce;
zend_string *name;
- zval property;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &name) == FAILURE) {
return;
@@ -4170,12 +4143,9 @@ ZEND_METHOD(reflection_class, hasProperty)
RETURN_TRUE;
} else {
if (Z_TYPE(intern->obj) != IS_UNDEF) {
- ZVAL_STR_COPY(&property, name);
- if (Z_OBJ_HANDLER(intern->obj, has_property)(&intern->obj, &property, 2, NULL)) {
- zval_ptr_dtor(&property);
+ if (Z_OBJ_HANDLER(intern->obj, has_property)(Z_OBJ(intern->obj), name, 2, NULL)) {
RETURN_TRUE;
}
- zval_ptr_dtor(&property);
}
RETURN_FALSE;
}
@@ -4205,7 +4175,7 @@ ZEND_METHOD(reflection_class, getProperty)
}
} else if (Z_TYPE(intern->obj) != IS_UNDEF) {
/* Check for dynamic properties */
- if (zend_hash_exists(Z_OBJ_HT(intern->obj)->get_properties(&intern->obj), name)) {
+ if (zend_hash_exists(Z_OBJ_HT(intern->obj)->get_properties(Z_OBJ(intern->obj)), name)) {
zend_property_info property_info_tmp;
property_info_tmp.flags = ZEND_ACC_PUBLIC;
property_info_tmp.name = name;
@@ -4324,7 +4294,7 @@ ZEND_METHOD(reflection_class, getProperties)
} ZEND_HASH_FOREACH_END();
if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) {
- HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(&intern->obj);
+ HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(Z_OBJ(intern->obj));
zval *prop;
ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) {
_adddynproperty(prop, key, ce, return_value);
@@ -4589,7 +4559,7 @@ ZEND_METHOD(reflection_class, isInstance)
}
/* }}} */
-/* {{{ proto public object ReflectionClass::newInstance(mixed* args, ...)
+/* {{{ proto public object ReflectionClass::newInstance([mixed* args], ...)
Returns an instance of this class */
ZEND_METHOD(reflection_class, newInstance)
{
@@ -5235,7 +5205,7 @@ ZEND_METHOD(reflection_property, __construct)
&& property_info->ce != ce)) {
/* Check for dynamic properties */
if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT) {
- if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name)) {
+ if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(Z_OBJ_P(classname)), name)) {
dynam_prop = 1;
}
}
@@ -5494,11 +5464,10 @@ ZEND_METHOD(reflection_property, isInitialized)
if (ref->prop.flags & ZEND_ACC_STATIC) {
member_p = zend_read_static_property_ex(intern->ce, ref->unmangled_name, 1);
if (member_p) {
- RETURN_BOOL(!Z_ISUNDEF_P(member_p))
+ RETURN_BOOL(!Z_ISUNDEF_P(member_p));
}
RETURN_FALSE;
} else {
- zval name_zv;
zend_class_entry *old_scope;
int retval;
@@ -5513,8 +5482,7 @@ ZEND_METHOD(reflection_property, isInitialized)
old_scope = EG(fake_scope);
EG(fake_scope) = intern->ce;
- ZVAL_STR(&name_zv, ref->unmangled_name);
- retval = Z_OBJ_HT_P(object)->has_property(object, &name_zv, ZEND_PROPERTY_EXISTS, NULL);
+ retval = Z_OBJ_HT_P(object)->has_property(Z_OBJ_P(object), ref->unmangled_name, ZEND_PROPERTY_EXISTS, NULL);
EG(fake_scope) = old_scope;
RETVAL_BOOL(retval);
@@ -6267,7 +6235,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_function___construct, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_function_invoke, 0, 0, 0)
- ZEND_ARG_INFO(0, args)
+ ZEND_ARG_VARIADIC_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_reflection_function_invokeArgs, 0)
@@ -6345,9 +6313,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method___construct, 0, 0, 1)
ZEND_ARG_INFO(0, name)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_invoke, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_method_invoke, 0, 0, 1)
ZEND_ARG_INFO(0, object)
- ZEND_ARG_INFO(0, args)
+ ZEND_ARG_VARIADIC_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_reflection_method_invokeArgs, 0)
@@ -6441,8 +6409,8 @@ ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_isInstance, 0)
ZEND_ARG_INFO(0, object)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstance, 0)
- ZEND_ARG_INFO(0, args)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_reflection_class_newInstance, 0, 0, 0)
+ ZEND_ARG_VARIADIC_INFO(0, args)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_reflection_class_newInstanceWithoutConstructor, 0)
@@ -6653,13 +6621,13 @@ static const zend_function_entry reflection_parameter_functions[] = {
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, ZEND_ACC_DEPRECATED)
PHP_FE_END
};
static const zend_function_entry reflection_named_type_functions[] = {
ZEND_ME(reflection_named_type, getName, arginfo_reflection__void, 0)
+ ZEND_ME(reflection_named_type, isBuiltin, arginfo_reflection__void, 0)
PHP_FE_END
};
@@ -6729,20 +6697,19 @@ static const zend_function_entry reflection_ext_functions[] = { /* {{{ */
}; /* }}} */
/* {{{ _reflection_write_property */
-static zval *_reflection_write_property(zval *object, zval *member, zval *value, void **cache_slot)
+static zval *_reflection_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
{
- if ((Z_TYPE_P(member) == IS_STRING)
- && 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")))))
+ if (zend_hash_exists(&object->ce->properties_info, name)
+ && ((ZSTR_LEN(name) == sizeof("name") - 1 && !memcmp(ZSTR_VAL(name), "name", sizeof("name")))
+ || (ZSTR_LEN(name) == sizeof("class") - 1 && !memcmp(ZSTR_VAL(name), "class", sizeof("class")))))
{
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));
+ "Cannot set read-only property %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
return &EG(uninitialized_zval);
}
else
{
- return zend_std_write_property(object, member, value, cache_slot);
+ return zend_std_write_property(object, name, value, cache_slot);
}
}
/* }}} */
@@ -6799,6 +6766,7 @@ PHP_MINIT_FUNCTION(reflection) /* {{{ */
INIT_CLASS_ENTRY(_reflection_entry, "ReflectionType", reflection_type_functions);
reflection_init_class_handlers(&_reflection_entry);
reflection_type_ptr = zend_register_internal_class(&_reflection_entry);
+ reflection_type_ptr->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
INIT_CLASS_ENTRY(_reflection_entry, "ReflectionNamedType", reflection_named_type_functions);
reflection_init_class_handlers(&_reflection_entry);