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.c153
1 files changed, 86 insertions, 67 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index c2f6e198ad..c82e29702a 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -75,29 +75,28 @@ PHPAPI zend_class_entry *reflection_extension_ptr;
PHPAPI zend_class_entry *reflection_zend_extension_ptr;
/* Exception throwing macro */
-#define _DO_THROW(msg) \
- zend_throw_exception(reflection_exception_ptr, msg, 0); \
- return; \
-
-#define RETURN_ON_EXCEPTION \
- if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { \
- return; \
- }
-
-#define GET_REFLECTION_OBJECT() \
- intern = Z_REFLECTION_P(getThis()); \
- if (intern->ptr == NULL) { \
- RETURN_ON_EXCEPTION \
- zend_throw_error(NULL, "Internal error: Failed to retrieve the reflection object"); \
- return; \
- } \
+#define _DO_THROW(msg) \
+ zend_throw_exception(reflection_exception_ptr, msg, 0); \
+ return;
+
+#define GET_REFLECTION_OBJECT() do { \
+ intern = Z_REFLECTION_P(getThis()); \
+ if (intern->ptr == NULL) { \
+ if (EG(exception) && EG(exception)->ce == reflection_exception_ptr) { \
+ return; \
+ } \
+ zend_throw_error(NULL, "Internal error: Failed to retrieve the reflection object"); \
+ return; \
+ } \
+} while (0)
-#define GET_REFLECTION_OBJECT_PTR(target) \
- GET_REFLECTION_OBJECT() \
- target = intern->ptr; \
+#define GET_REFLECTION_OBJECT_PTR(target) do { \
+ GET_REFLECTION_OBJECT(); \
+ target = intern->ptr; \
+} while (0)
/* Class constants */
-#define REGISTER_REFLECTION_CLASS_CONST_LONG(class_name, const_name, value) \
+#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, (zend_long)value);
/* {{{ Object structure */
@@ -107,6 +106,7 @@ typedef struct _property_reference {
zend_class_entry *ce;
zend_property_info prop;
zend_string *unmangled_name;
+ zend_bool dynamic;
} property_reference;
/* Struct for parameters */
@@ -135,7 +135,6 @@ typedef enum {
/* Struct for reflection objects */
typedef struct {
- zval dummy; /* holder for the second property */
zval obj;
void *ptr;
zend_class_entry *ce;
@@ -266,7 +265,7 @@ static zval *reflection_instantiate(zend_class_entry *pce, zval *object) /* {{{
static void _const_string(smart_str *str, char *name, zval *value, char *indent);
static void _function_string(smart_str *str, zend_function *fptr, zend_class_entry *scope, char* indent);
-static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent);
+static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent, zend_bool dynamic);
static void _class_const_string(smart_str *str, char *name, zend_class_constant *c, char* indent);
static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char *indent);
static void _extension_string(smart_str *str, zend_module_entry *module, char *indent);
@@ -324,6 +323,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
if (ce->num_interfaces) {
uint32_t i;
+ ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED);
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
smart_str_append_printf(str, " extends %s", ZSTR_VAL(ce->interfaces[0]->name));
} else {
@@ -365,7 +365,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
zend_property_info *prop;
ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) {
- if(prop->flags & ZEND_ACC_SHADOW) {
+ if ((prop->flags & ZEND_ACC_PRIVATE) && prop->ce != ce) {
count_shadow_props++;
} else if (prop->flags & ZEND_ACC_STATIC) {
count_static_props++;
@@ -379,8 +379,8 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
zend_property_info *prop;
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));
+ if ((prop->flags & ZEND_ACC_STATIC) && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) {
+ _property_string(str, prop, NULL, ZSTR_VAL(sub_indent), 0);
}
} ZEND_HASH_FOREACH_END();
}
@@ -426,8 +426,9 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
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));
+ if (!(prop->flags & ZEND_ACC_STATIC)
+ && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) {
+ _property_string(str, prop, NULL, ZSTR_VAL(sub_indent), 0);
}
} ZEND_HASH_FOREACH_END();
}
@@ -444,7 +445,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
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(&prop_str, NULL, ZSTR_VAL(prop_name), ZSTR_VAL(sub_indent));
+ _property_string(&prop_str, NULL, ZSTR_VAL(prop_name), ZSTR_VAL(sub_indent), 0);
}
}
} ZEND_HASH_FOREACH_END();
@@ -471,7 +472,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
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
+ if (mptr->common.scope->constructor != mptr
|| mptr->common.scope == ce
|| !key
|| zend_binary_strcasecmp(ZSTR_VAL(key), ZSTR_LEN(key), ZSTR_VAL(mptr->common.function_name), len) == 0)
@@ -743,10 +744,10 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
if (fptr->common.prototype && fptr->common.prototype->common.scope) {
smart_str_append_printf(str, ", prototype %s", ZSTR_VAL(fptr->common.prototype->common.scope->name));
}
- if (fptr->common.fn_flags & ZEND_ACC_CTOR) {
+ if (fptr->common.scope && fptr->common.scope->constructor == fptr) {
smart_str_appends(str, ", ctor");
}
- if (fptr->common.fn_flags & ZEND_ACC_DTOR) {
+ if (fptr->common.scope && fptr->common.scope->destructor == fptr) {
smart_str_appends(str, ", dtor");
}
smart_str_appends(str, "> ");
@@ -821,14 +822,14 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
/* }}} */
/* {{{ _property_string */
-static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent)
+static void _property_string(smart_str *str, zend_property_info *prop, const char *prop_name, char* indent, zend_bool dynamic)
{
smart_str_append_printf(str, "%sProperty [ ", indent);
if (!prop) {
smart_str_append_printf(str, "<dynamic> public $%s", prop_name);
} else {
if (!(prop->flags & ZEND_ACC_STATIC)) {
- if (prop->flags & ZEND_ACC_IMPLICIT_PUBLIC) {
+ if (dynamic) {
smart_str_appends(str, "<implicit> ");
} else {
smart_str_appends(str, "<default> ");
@@ -1224,7 +1225,7 @@ static void reflection_method_factory(zend_class_entry *ce, zend_function *metho
/* }}} */
/* {{{ reflection_property_factory */
-static void reflection_property_factory(zend_class_entry *ce, zend_string *name, zend_property_info *prop, zval *object)
+static void reflection_property_factory(zend_class_entry *ce, zend_string *name, zend_property_info *prop, zval *object, zend_bool dynamic)
{
reflection_object *intern;
zval propname;
@@ -1241,7 +1242,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_string *name,
tmp_ce = tmp_ce->parent;
}
- if (tmp_info && !(tmp_info->flags & ZEND_ACC_SHADOW)) { /* found something and it's not a parent's private */
+ if (tmp_info && (!(tmp_info->flags & ZEND_ACC_PRIVATE) || tmp_info->ce == tmp_ce)) { /* found something and it's not a parent's private */
prop = tmp_info;
} else { /* not found, use initial value */
ce = store_ce;
@@ -1257,6 +1258,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_string *name,
reference->ce = ce;
reference->prop = *prop;
reference->unmangled_name = zend_string_copy(name);
+ reference->dynamic = dynamic;
intern->ptr = reference;
intern->ref_type = REF_TYPE_PROPERTY;
intern->ce = ce;
@@ -1269,7 +1271,7 @@ static void reflection_property_factory(zend_class_entry *ce, zend_string *name,
static void reflection_property_factory_str(zend_class_entry *ce, const char *name_str, size_t name_len, zend_property_info *prop, zval *object)
{
zend_string *name = zend_string_init(name_str, name_len, 0);
- reflection_property_factory(ce, name, prop, object);
+ reflection_property_factory(ce, name, prop, object, 0);
zend_string_release(name);
}
@@ -1493,9 +1495,6 @@ ZEND_METHOD(reflection, getModifierNames)
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);
- }
/* These are mutually exclusive */
switch (modifiers & ZEND_ACC_PPP_MASK) {
@@ -3408,7 +3407,7 @@ ZEND_METHOD(reflection_method, isConstructor)
/* we need to check if the ctor is the ctor of the class level we we
* looking at since we might be looking at an inherited old style ctor
* defined in base class. */
- RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_CTOR && intern->ce->constructor && intern->ce->constructor->common.scope == mptr->common.scope);
+ RETURN_BOOL(intern->ce->constructor == mptr);
}
/* }}} */
@@ -3423,7 +3422,7 @@ ZEND_METHOD(reflection_method, isDestructor)
return;
}
GET_REFLECTION_OBJECT_PTR(mptr);
- RETURN_BOOL(mptr->common.fn_flags & ZEND_ACC_DTOR);
+ RETURN_BOOL(intern->ce->destructor == mptr);
}
/* }}} */
@@ -3433,7 +3432,7 @@ ZEND_METHOD(reflection_method, getModifiers)
{
reflection_object *intern;
zend_function *mptr;
- uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_IMPLICIT_PUBLIC
+ uint32_t keep_flags = ZEND_ACC_PPP_MASK
| ZEND_ACC_STATIC | ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL;
if (zend_parse_parameters_none() == FAILURE) {
@@ -3603,7 +3602,7 @@ static void _class_constant_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /
Returns whether this constant is public */
ZEND_METHOD(reflection_class_constant, isPublic)
{
- _class_constant_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC);
+ _class_constant_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC);
}
/* }}} */
@@ -3763,9 +3762,7 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
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) &&
+ if (((prop_info->flags & ZEND_ACC_PROTECTED) &&
!zend_check_protected(prop_info->ce, ce)) ||
((prop_info->flags & ZEND_ACC_PRIVATE) &&
prop_info->ce != ce)) {
@@ -4219,7 +4216,7 @@ ZEND_METHOD(reflection_class, hasProperty)
GET_REFLECTION_OBJECT_PTR(ce);
if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) {
- if (property_info->flags & ZEND_ACC_SHADOW) {
+ if ((property_info->flags & ZEND_ACC_PRIVATE) && property_info->ce != ce) {
RETURN_FALSE;
}
RETURN_TRUE;
@@ -4254,20 +4251,20 @@ ZEND_METHOD(reflection_class, getProperty)
GET_REFLECTION_OBJECT_PTR(ce);
if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) != NULL) {
- if ((property_info->flags & ZEND_ACC_SHADOW) == 0) {
- reflection_property_factory(ce, name, property_info, return_value);
+ if (!(property_info->flags & ZEND_ACC_PRIVATE) || property_info->ce == ce) {
+ reflection_property_factory(ce, name, property_info, return_value, 0);
return;
}
} 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)) {
zend_property_info property_info_tmp;
- property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC;
+ property_info_tmp.flags = ZEND_ACC_PUBLIC;
property_info_tmp.name = name;
property_info_tmp.doc_comment = NULL;
property_info_tmp.ce = ce;
- reflection_property_factory(ce, name, &property_info_tmp, return_value);
+ reflection_property_factory(ce, name, &property_info_tmp, return_value, 1);
return;
}
}
@@ -4296,7 +4293,10 @@ ZEND_METHOD(reflection_class, getProperty)
}
ce = ce2;
- if ((property_info = zend_hash_str_find_ptr(&ce->properties_info, str_name, str_name_len)) != NULL && (property_info->flags & ZEND_ACC_SHADOW) == 0) {
+ property_info = zend_hash_str_find_ptr(&ce->properties_info, str_name, str_name_len);
+ if (property_info != NULL
+ && (!(property_info->flags & ZEND_ACC_PRIVATE)
+ || property_info->ce == ce)) {
reflection_property_factory_str(ce, str_name, str_name_len, property_info, return_value);
return;
}
@@ -4315,7 +4315,7 @@ static int _addproperty(zval *el, int num_args, va_list args, zend_hash_key *has
zval *retval = va_arg(args, zval*);
long filter = va_arg(args, long);
- if (pptr->flags & ZEND_ACC_SHADOW) {
+ if ((pptr->flags & ZEND_ACC_PRIVATE) && pptr->ce != ce) {
return 0;
}
@@ -4338,7 +4338,7 @@ static int _adddynproperty(zval *ptr, int num_args, va_list args, zend_hash_key
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
+ * properties (e.g. when casting from array). This is a WON'T FIX bug, at
* least for the moment. Ignore these */
if (hash_key->key == NULL) {
return 0;
@@ -4352,11 +4352,11 @@ static int _adddynproperty(zval *ptr, int num_args, va_list args, zend_hash_key
zend_property_info property_info;
property_info.doc_comment = NULL;
- property_info.flags = ZEND_ACC_IMPLICIT_PUBLIC;
+ property_info.flags = ZEND_ACC_PUBLIC;
property_info.name = hash_key->key;
property_info.ce = ce;
property_info.offset = -1;
- reflection_property_factory(ce, hash_key->key, &property_info, &property);
+ reflection_property_factory(ce, hash_key->key, &property_info, &property, 1);
add_next_index_zval(retval, &property);
}
return 0;
@@ -4829,6 +4829,7 @@ ZEND_METHOD(reflection_class, getInterfaces)
if (ce->num_interfaces) {
uint32_t i;
+ ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED);
array_init(return_value);
for (i=0; i < ce->num_interfaces; i++) {
zval interface;
@@ -4860,6 +4861,7 @@ ZEND_METHOD(reflection_class, getInterfaceNames)
return;
}
+ ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED);
array_init(return_value);
for (i=0; i < ce->num_interfaces; i++) {
@@ -4890,8 +4892,13 @@ ZEND_METHOD(reflection_class, getTraits)
for (i=0; i < ce->num_traits; i++) {
zval trait;
- zend_reflection_class_factory(ce->traits[i], &trait);
- zend_hash_update(Z_ARRVAL_P(return_value), ce->traits[i]->name, &trait);
+ zend_class_entry *trait_ce;
+
+ trait_ce = zend_fetch_class_by_name(ce->trait_names[i].name,
+ ce->trait_names[i].lc_name, ZEND_FETCH_CLASS_TRAIT);
+ ZEND_ASSERT(trait_ce);
+ zend_reflection_class_factory(trait_ce, &trait);
+ zend_hash_update(Z_ARRVAL_P(return_value), ce->trait_names[i].name, &trait);
}
}
/* }}} */
@@ -4917,7 +4924,7 @@ ZEND_METHOD(reflection_class, getTraitNames)
array_init(return_value);
for (i=0; i < ce->num_traits; i++) {
- add_next_index_str(return_value, zend_string_copy(ce->traits[i]->name));
+ add_next_index_str(return_value, zend_string_copy(ce->trait_names[i].name));
}
}
/* }}} */
@@ -5270,7 +5277,10 @@ ZEND_METHOD(reflection_property, __construct)
/* returns out of this function */
}
- if ((property_info = zend_hash_find_ptr(&ce->properties_info, name)) == NULL || (property_info->flags & ZEND_ACC_SHADOW)) {
+ property_info = zend_hash_find_ptr(&ce->properties_info, name);
+ if (property_info == NULL
+ || ((property_info->flags & ZEND_ACC_PRIVATE)
+ && property_info->ce != ce)) {
/* 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), name)) {
@@ -5307,12 +5317,14 @@ ZEND_METHOD(reflection_property, __construct)
reference = (property_reference*) emalloc(sizeof(property_reference));
if (dynam_prop) {
- reference->prop.flags = ZEND_ACC_IMPLICIT_PUBLIC;
+ reference->prop.flags = ZEND_ACC_PUBLIC;
reference->prop.name = name;
reference->prop.doc_comment = NULL;
reference->prop.ce = ce;
+ reference->dynamic = 1;
} else {
reference->prop = *property_info;
+ reference->dynamic = 0;
}
reference->ce = ce;
reference->unmangled_name = zend_string_copy(name);
@@ -5335,7 +5347,7 @@ ZEND_METHOD(reflection_property, __toString)
return;
}
GET_REFLECTION_OBJECT_PTR(ref);
- _property_string(&str, &ref->prop, ZSTR_VAL(ref->unmangled_name), "");
+ _property_string(&str, &ref->prop, ZSTR_VAL(ref->unmangled_name), "", ref->dynamic);
RETURN_STR(smart_str_extract(&str));
}
/* }}} */
@@ -5368,7 +5380,7 @@ static void _property_check_flag(INTERNAL_FUNCTION_PARAMETERS, int mask) /* {{{
Returns whether this property is public */
ZEND_METHOD(reflection_property, isPublic)
{
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC);
+ _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_PUBLIC);
}
/* }}} */
@@ -5400,7 +5412,14 @@ ZEND_METHOD(reflection_property, isStatic)
Returns whether this property is default (declared at compilation time). */
ZEND_METHOD(reflection_property, isDefault)
{
- _property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ~ZEND_ACC_IMPLICIT_PUBLIC);
+ reflection_object *intern;
+ property_reference *ref;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+ GET_REFLECTION_OBJECT_PTR(ref);
+ RETURN_BOOL(!ref->dynamic);
}
/* }}} */
@@ -5410,7 +5429,7 @@ ZEND_METHOD(reflection_property, getModifiers)
{
reflection_object *intern;
property_reference *ref;
- uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_IMPLICIT_PUBLIC | ZEND_ACC_STATIC;
+ uint32_t keep_flags = ZEND_ACC_PPP_MASK | ZEND_ACC_STATIC;
if (zend_parse_parameters_none() == FAILURE) {
return;
@@ -5432,7 +5451,7 @@ ZEND_METHOD(reflection_property, getValue)
GET_REFLECTION_OBJECT_PTR(ref);
- if (!(ref->prop.flags & (ZEND_ACC_PUBLIC | ZEND_ACC_IMPLICIT_PUBLIC)) && intern->ignore_visibility == 0) {
+ if (!(ref->prop.flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) {
name = _default_load_name(getThis());
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Cannot access non-public member %s::$%s", ZSTR_VAL(intern->ce->name), Z_STRVAL_P(name));
@@ -5522,7 +5541,7 @@ ZEND_METHOD(reflection_property, getDeclaringClass)
ce = tmp_ce = ref->ce;
while (tmp_ce && (tmp_info = zend_hash_find_ptr(&tmp_ce->properties_info, ref->unmangled_name)) != NULL) {
- if (tmp_info->flags & ZEND_ACC_PRIVATE || tmp_info->flags & ZEND_ACC_SHADOW) {
+ if (tmp_info->flags & ZEND_ACC_PRIVATE) {
/* it's a private property, so it can't be inherited */
break;
}