zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
zend_standard_class_def->parent = NULL;
zend_hash_init_ex(&zend_standard_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
- zend_hash_init_ex(&zend_standard_class_def->default_properties_info, 0, NULL, (dtor_func_t) zend_destroy_property_info, 1, 0);
+ zend_hash_init_ex(&zend_standard_class_def->properties_info, 0, NULL, (dtor_func_t) zend_destroy_property_info, 1, 0);
zend_standard_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
zend_hash_init_ex(zend_standard_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
HashTable function_table;
HashTable default_properties;
- HashTable default_properties_info;
+ HashTable properties_info;
HashTable class_table;
HashTable *static_members;
HashTable constants_table;
class_entry->constants_updated = 0;
class_entry->ce_flags = 0;
zend_hash_init(&class_entry->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1);
- zend_hash_init(&class_entry->default_properties_info, 0, NULL, NULL, 1);
+ zend_hash_init(&class_entry->properties_info, 0, NULL, NULL, 1);
class_entry->static_members = (HashTable *) malloc(sizeof(HashTable));
zend_hash_init(class_entry->static_members, 0, NULL, ZVAL_PTR_DTOR, 1);
zend_hash_init(&class_entry->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1);
return 0; /* don't copy access information to child */
}
- if (zend_hash_quick_find(&ce->default_properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child_info)==SUCCESS) {
+ if (zend_hash_quick_find(&ce->properties_info, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void **) &child_info)==SUCCESS) {
if ((child_info->flags & ZEND_ACC_PPP_MASK) > (parent_info->flags & ZEND_ACC_PPP_MASK)) {
zend_error(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ce->name, hash_key->arKey, zend_visibility_string(parent_info->flags), parent_ce->name, (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
}
/* Inherit properties */
zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, (void (*)(void *)) zval_add_ref, NULL, sizeof(zval *), 0);
- zend_hash_merge_ex(&ce->default_properties_info, &parent_ce->default_properties_info, (copy_ctor_func_t) zend_duplicate_property_info, sizeof(zend_property_info), (merge_checker_func_t) do_inherit_property_access_check, ce);
+ zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info, (copy_ctor_func_t) zend_duplicate_property_info, sizeof(zend_property_info), (merge_checker_func_t) do_inherit_property_access_check, ce);
/* STATIC_MEMBERS_FIXME */
/* zend_hash_merge(ce->static_members, parent_ce->static_members, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0); */
zend_hash_init(&new_class_entry->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
zend_hash_init(&new_class_entry->class_table, 10, NULL, ZEND_CLASS_DTOR, 0);
zend_hash_init(&new_class_entry->default_properties, 10, NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_init(&new_class_entry->default_properties_info, 10, NULL, NULL, 0);
+ zend_hash_init(&new_class_entry->properties_info, 10, NULL, NULL, 0);
ALLOC_HASHTABLE(new_class_entry->static_members);
zend_hash_init(new_class_entry->static_members, 10, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_init(&new_class_entry->constants_table, 10, NULL, ZVAL_PTR_DTOR, 0);
ce->refcount--;
zend_hash_destroy(&ce->function_table);
zend_hash_destroy(&ce->default_properties);
- zend_hash_destroy(&ce->default_properties_info);
+ zend_hash_destroy(&ce->properties_info);
zend_hash_destroy(ce->static_members);
zend_hash_destroy(&ce->constants_table);
return FAILURE;
zend_hash_init(&new_class_entry->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0);
zend_hash_init(&new_class_entry->class_table, 10, NULL, ZEND_CLASS_DTOR, 0);
zend_hash_init(&new_class_entry->default_properties, 10, NULL, ZVAL_PTR_DTOR, 0);
- zend_hash_init(&new_class_entry->default_properties_info, 10, NULL, NULL, 0);
+ zend_hash_init(&new_class_entry->properties_info, 10, NULL, NULL, 0);
ALLOC_HASHTABLE(new_class_entry->static_members);
zend_hash_init(new_class_entry->static_members, 10, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_init(&new_class_entry->constants_table, 10, NULL, ZVAL_PTR_DTOR, 0);
{
zval *property;
zend_property_info property_info;
+ HashTable *target_symbol_table;
ALLOC_ZVAL(property);
}
if (CG(access_type) & ZEND_ACC_STATIC) {
- /* FIXME: Currently, ignores access type for static variables */
- zend_hash_update(CG(active_class_entry)->static_members, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
- FREE_PNODE(var_name);
- return;
+ target_symbol_table = CG(active_class_entry)->static_members;
+ } else {
+ target_symbol_table = &CG(active_class_entry)->default_properties;
}
- switch (CG(access_type)) {
+ switch (CG(access_type) & ZEND_ACC_PPP_MASK) {
case ZEND_ACC_PRIVATE: {
char *priv_name;
int priv_name_length;
mangle_property_name(&priv_name, &priv_name_length, CG(active_class_entry)->name, CG(active_class_entry)->name_length, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len);
- zend_hash_update(&CG(active_class_entry)->default_properties, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL);
+ zend_hash_update(target_symbol_table, priv_name, priv_name_length+1, &property, sizeof(zval *), NULL);
property_info.name = priv_name;
property_info.name_length = priv_name_length;
}
int prot_name_length;
mangle_property_name(&prot_name, &prot_name_length, "*", 1, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len);
- zend_hash_update(&CG(active_class_entry)->default_properties, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL);
+ zend_hash_update(target_symbol_table, prot_name, prot_name_length+1, &property, sizeof(zval *), NULL);
property_info.name = prot_name;
property_info.name_length = prot_name_length;
}
break;
case ZEND_ACC_PUBLIC:
- zend_hash_update(&CG(active_class_entry)->default_properties, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
+ zend_hash_update(target_symbol_table, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL);
property_info.name = var_name->u.constant.value.str.val;
property_info.name_length = var_name->u.constant.value.str.len;
break;
property_info.flags = CG(access_type);
property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1);
- zend_hash_update(&CG(active_class_entry)->default_properties_info, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property_info, sizeof(zend_property_info), NULL);
-
- /*FREE_PNODE(var_name);*/
+ zend_hash_update(&CG(active_class_entry)->properties_info, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property_info, sizeof(zend_property_info), NULL);
}
print_refcount(NULL, NULL);
}
-static inline HashTable *zend_find_inherited_static(zend_class_entry *ce, zval *variable)
-{
- zend_class_entry *orig_ce = ce;
-
- while (ce) {
- if (zend_hash_exists(ce->static_members, Z_STRVAL_P(variable), Z_STRLEN_P(variable)+1)) {
- return ce->static_members;
- }
- ce = ce->parent;
- }
- return orig_ce->static_members;
-}
static inline HashTable *zend_get_target_symbol_table(zend_op *opline, temp_variable *Ts, int type, zval *variable TSRMLS_DC)
{
}
return EG(active_op_array)->static_variables;
break;
- case ZEND_FETCH_STATIC_MEMBER:
- if (T(opline->op2.u.var).EA.class_entry->parent) {
- /* if inherited, try to look up */
- return zend_find_inherited_static(T(opline->op2.u.var).EA.class_entry, variable);
- } else {
- /* if class is not inherited, no point in checking */
- return T(opline->op2.u.var).EA.class_entry->static_members;
- }
- break;
EMPTY_SWITCH_DEFAULT_CASE()
}
return NULL;
varname = &tmp_varname;
}
- target_symbol_table = zend_get_target_symbol_table(opline, Ts, type, varname TSRMLS_CC);
- if (!target_symbol_table) {
- return;
- }
+ if (opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
+ target_symbol_table = NULL;
+ retval = zend_get_static_property(T(opline->op2.u.var).EA.class_entry, Z_STRVAL_P(varname), Z_STRLEN_P(varname), type TSRMLS_CC);
+ } else {
+ target_symbol_table = zend_get_target_symbol_table(opline, Ts, type, varname TSRMLS_CC);
+ if (!target_symbol_table) {
+ return;
+ }
+ if (zend_hash_find(target_symbol_table, varname->value.str.val, varname->value.str.len+1, (void **) &retval) == FAILURE) {
+ switch (type) {
+ case BP_VAR_R:
+ zend_error(E_NOTICE,"Undefined variable: %s", varname->value.str.val);
+ /* break missing intentionally */
+ case BP_VAR_IS:
+ retval = &EG(uninitialized_zval_ptr);
+ break;
+ case BP_VAR_RW:
+ zend_error(E_NOTICE,"Undefined variable: %s", varname->value.str.val);
+ /* break missing intentionally */
+ case BP_VAR_W: {
+ zval *new_zval = &EG(uninitialized_zval);
- if (zend_hash_find(target_symbol_table, varname->value.str.val, varname->value.str.len+1, (void **) &retval) == FAILURE) {
- switch (type) {
- case BP_VAR_R:
- zend_error(E_NOTICE,"Undefined variable: %s", varname->value.str.val);
- /* break missing intentionally */
- case BP_VAR_IS:
- retval = &EG(uninitialized_zval_ptr);
+ new_zval->refcount++;
+ zend_hash_update(target_symbol_table, varname->value.str.val, varname->value.str.len+1, &new_zval, sizeof(zval *), (void **) &retval);
+ }
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE()
+ }
+ }
+ switch (opline->op2.u.EA.type) {
+ case ZEND_FETCH_LOCAL:
+ FREE_OP(Ts, &opline->op1, free_op1);
break;
- case BP_VAR_RW:
- zend_error(E_NOTICE,"Undefined variable: %s", varname->value.str.val);
- /* break missing intentionally */
- case BP_VAR_W: {
- zval *new_zval = &EG(uninitialized_zval);
-
- new_zval->refcount++;
- zend_hash_update(target_symbol_table, varname->value.str.val, varname->value.str.len+1, &new_zval, sizeof(zval *), (void **) &retval);
- }
+ case ZEND_FETCH_STATIC:
+ zval_update_constant(retval, (void *) 1 TSRMLS_CC);
break;
- EMPTY_SWITCH_DEFAULT_CASE()
}
}
- if (opline->op2.u.EA.type == ZEND_FETCH_LOCAL) {
- FREE_OP(Ts, &opline->op1, free_op1);
- } else if (opline->op2.u.EA.type == ZEND_FETCH_STATIC || opline->op2.u.EA.type == ZEND_FETCH_STATIC_MEMBER) {
- zval_update_constant(retval, (void *) 1 TSRMLS_CC);
- }
+
if (varname == &tmp_varname) {
zval_dtor(varname);
}
-inline int zend_verify_property_access(zend_property_info *property_info, zend_object *zobj TSRMLS_DC)
+inline int zend_verify_property_access(zend_property_info *property_info, zend_class_entry *ce TSRMLS_DC)
{
switch (property_info->flags & ZEND_ACC_PPP_MASK) {
case ZEND_ACC_PUBLIC:
return 1;
case ZEND_ACC_PRIVATE:
- if (zobj->ce == EG(scope)) {
+ if (ce == EG(scope)) {
return 1;
} else {
return 0;
}
break;
- case ZEND_ACC_PROTECTED: {
- zend_class_entry *ce = zobj->ce;
-
- while (ce) {
- if (ce==EG(scope)) {
- return 1;
- }
- ce = ce->parent;
+ case ZEND_ACC_PROTECTED:
+ while (ce) {
+ if (ce==EG(scope)) {
+ return 1;
}
- return 0;
- }
- break;
+ ce = ce->parent;
+ }
+ return 0;
}
return 0;
}
fprintf(stderr, "Read object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
#endif
- if (zend_hash_find(&zobj->ce->default_properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &property_info)==FAILURE) {
+ if (zend_hash_find(&zobj->ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &property_info)==FAILURE) {
std_property_info.flags = ZEND_ACC_PUBLIC;
std_property_info.name = Z_STRVAL_P(member);
std_property_info.name_length = Z_STRLEN_P(member);
#if DEBUG_OBJECT_HANDLERS
zend_printf("Access type for %s::%s is %s\n", zobj->ce->name, Z_STRVAL_P(member), zend_visibility_string(property_info->flags));
#endif
- if (!zend_verify_property_access(property_info, zobj TSRMLS_CC)) {
+ if (!zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) {
zend_error(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), zobj->ce->name, Z_STRVAL_P(member));
}
member = &tmp_member;
}
- if (zend_hash_find(&zobj->ce->default_properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &property_info)==FAILURE) {
+ if (zend_hash_find(&zobj->ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &property_info)==FAILURE) {
std_property_info.flags = ZEND_ACC_PUBLIC;
std_property_info.name = Z_STRVAL_P(member);
std_property_info.name_length = Z_STRLEN_P(member);
zend_printf("Access type for %s::%s is %s\n", zobj->ce->name, Z_STRVAL_P(member), zend_visibility_string(property_info->flags));
#endif
- if (!zend_verify_property_access(property_info, zobj TSRMLS_CC)) {
+ if (!zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) {
zend_error(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), zobj->ce->name, Z_STRVAL_P(member));
}
member = &tmp_member;
}
- if (zend_hash_find(&zobj->ce->default_properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &property_info)==FAILURE) {
+ if (zend_hash_find(&zobj->ce->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &property_info)==FAILURE) {
std_property_info.flags = ZEND_ACC_PUBLIC;
std_property_info.name = Z_STRVAL_P(member);
std_property_info.name_length = Z_STRLEN_P(member);
fprintf(stderr, "Ptr object #%d property: %s\n", Z_OBJ_HANDLE_P(object), Z_STRVAL_P(member));
#endif
- if (!zend_verify_property_access(property_info, zobj TSRMLS_CC)) {
+ if (!zend_verify_property_access(property_info, zobj->ce TSRMLS_CC)) {
zend_error(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), zobj->ce->name, Z_STRVAL_P(member));
}
}
+zval **zend_get_static_property(zend_class_entry *ce, char *property_name, int property_name_len, int type TSRMLS_DC)
+{
+ HashTable *statics_table;
+ zval **retval = NULL;
+ zend_class_entry *tmp_ce = ce;
+ zend_property_info *property_info;
+ zend_property_info std_property_info;
+
+ if (zend_hash_find(&ce->properties_info, property_name, property_name_len+1, (void **) &property_info)==FAILURE) {
+ std_property_info.flags = ZEND_ACC_PUBLIC;
+ std_property_info.name = property_name;
+ std_property_info.name_length = property_name_len;
+ std_property_info.h = zend_get_hash_value(std_property_info.name, std_property_info.name_length+1);
+ property_info = &std_property_info;
+ }
+
+#if 1&&DEBUG_OBJECT_HANDLERS
+ zend_printf("Access type for %s::%s is %s\n", ce->name, property_name, zend_visibility_string(property_info->flags));
+#endif
+
+ if (!zend_verify_property_access(property_info, ce TSRMLS_CC)) {
+ zend_error(E_ERROR, "Cannot access %s property %s::$%s", zend_visibility_string(property_info->flags), ce->name, property_name);
+ }
+
+ while (tmp_ce) {
+ if (zend_hash_quick_find(tmp_ce->static_members, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval)==SUCCESS) {
+ statics_table = tmp_ce->static_members;
+ break;
+ }
+ tmp_ce = tmp_ce->parent;
+ }
+
+ if (!retval) {
+ switch (type) {
+ case BP_VAR_R:
+ zend_error(E_NOTICE,"Undefined variable: %s::$%s", ce->name, property_name);
+ /* break missing intentionally */
+ case BP_VAR_IS:
+ retval = &EG(uninitialized_zval_ptr);
+ break;
+ case BP_VAR_RW:
+ zend_error(E_NOTICE,"Undefined variable: %s::$%s", ce->name, property_name);
+ /* break missing intentionally */
+ case BP_VAR_W: {
+ zval *new_zval = &EG(uninitialized_zval);
+
+ new_zval->refcount++;
+ zend_hash_quick_update(ce->static_members, property_info->name, property_info->name_length+1, property_info->h, &new_zval, sizeof(zval *), (void **) &retval);
+ }
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE()
+ }
+ }
+
+ return retval;
+}
+
+
static union _zend_function *zend_std_get_constructor(zval *object TSRMLS_DC)
{
zend_object *zobj = Z_OBJ_P(object);
extern zend_object_handlers std_object_handlers;
union _zend_function *zend_get_static_method(zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC);
+zval **zend_get_static_property(zend_class_entry *ce, char *property_name, int property_name_len, int type TSRMLS_DC);
#define IS_ZEND_STD_OBJECT(z) ((z).type == IS_OBJECT && (Z_OBJ_HT((z))->get_class_entry != NULL))
switch (ce->type) {
case ZEND_USER_CLASS:
zend_hash_destroy(&ce->default_properties);
- zend_hash_destroy(&ce->default_properties_info);
+ zend_hash_destroy(&ce->properties_info);
zend_hash_destroy(ce->static_members);
efree(ce->name);
zend_hash_destroy(&ce->function_table);
break;
case ZEND_INTERNAL_CLASS:
zend_hash_destroy(&ce->default_properties);
- zend_hash_destroy(&ce->default_properties_info);
+ zend_hash_destroy(&ce->properties_info);
zend_hash_destroy(ce->static_members);
free(ce->name);
zend_hash_destroy(&ce->function_table);