Skip to content

Commit

Permalink
Deal with ZEND_ACC_VIRTUAL properties consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jan 13, 2025
1 parent c70f217 commit 2d0d49f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ zval* pmmpthread_read_property(PMMPTHREAD_READ_PROPERTY_PASSTHRU_D) {
zend_property_info* info = zend_get_property_info(object->ce, member, 0);
if (info == ZEND_WRONG_PROPERTY_INFO) {
rv = &EG(uninitialized_zval);
} else if (info == NULL || (info->flags & ZEND_ACC_STATIC) != 0) { //dynamic property
} else if (info == NULL || !PMMPTHREAD_OBJECT_PROPERTY(info)) { //dynamic property
if (pmmpthread_store_read(object, &zmember, type, rv) == FAILURE) {
if (type != BP_VAR_IS) {
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(member));
Expand Down Expand Up @@ -161,7 +161,7 @@ zval* pmmpthread_write_property(PMMPTHREAD_WRITE_PROPERTY_PASSTHRU_D) {
bool ok = true;
zend_property_info* info = zend_get_property_info(object->ce, member, 0);
if (info != ZEND_WRONG_PROPERTY_INFO) {
if (info != NULL && (info->flags & ZEND_ACC_STATIC) == 0) {
if (info != NULL && PMMPTHREAD_OBJECT_PROPERTY(info)) {
ZVAL_STR(&zmember, info->name); //use mangled name to avoid private member shadowing issues

zend_execute_data* execute_data = EG(current_execute_data);
Expand Down Expand Up @@ -232,7 +232,7 @@ int pmmpthread_has_property(PMMPTHREAD_HAS_PROPERTY_PASSTHRU_D) {
} else {
zend_property_info* info = zend_get_property_info(object->ce, member, 1);
if (info != ZEND_WRONG_PROPERTY_INFO) {
if (info != NULL && (info->flags & ZEND_ACC_STATIC) == 0) {
if (info != NULL && PMMPTHREAD_OBJECT_PROPERTY(info)) {
ZVAL_STR(&zmember, info->name); //defined property, use mangled name
}
isset = pmmpthread_store_isset(object, &zmember, has_set_exists);
Expand Down Expand Up @@ -272,7 +272,7 @@ void pmmpthread_unset_property(PMMPTHREAD_UNSET_PROPERTY_PASSTHRU_D) {
} else {
zend_property_info* info = zend_get_property_info(object->ce, member, 0);
if (info != ZEND_WRONG_PROPERTY_INFO) {
if (info != NULL && (info->flags & ZEND_ACC_STATIC) == 0) {
if (info != NULL && PMMPTHREAD_OBJECT_PROPERTY(info)) {
ZVAL_STR(&zmember, info->name); //defined property, use mangled name
}
pmmpthread_store_delete(object, &zmember);
Expand Down
2 changes: 1 addition & 1 deletion src/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static inline void pmmpthread_base_write_property_defaults(pmmpthread_zend_objec
zval* value;
int result;

if (info->flags & ZEND_ACC_STATIC) {
if (!PMMPTHREAD_OBJECT_PROPERTY(info)) {
continue;
}

Expand Down
6 changes: 6 additions & 0 deletions src/pmmpthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ typedef struct _pmmpthread_call_t {

#define PMMPTHREAD_CALL_EMPTY {empty_fcall_info, empty_fcall_info_cache}

#if PHP_VERSION_ID >= 80400
#define PMMPTHREAD_OBJECT_PROPERTY(prop_info) ((prop_info->flags & (ZEND_ACC_STATIC | ZEND_ACC_VIRTUAL)) == 0)
#else
#define PMMPTHREAD_OBJECT_PROPERTY(prop_info) ((prop_info->flags & ZEND_ACC_STATIC) == 0)
#endif

/* this is a copy of the same struct in zend_closures.c, which unfortunately isn't exported */
typedef struct _zend_closure {
zend_object std;
Expand Down
6 changes: 1 addition & 5 deletions src/prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ static void prepare_class_property_table(const pmmpthread_ident_t* source, zend_
}

ZEND_HASH_FOREACH_PTR(&prepared->properties_info, info) {
if (info->ce == prepared && (info->flags & ZEND_ACC_STATIC) == 0
#if PHP_VERSION_ID >= 80400
&& (info->flags & ZEND_ACC_VIRTUAL) == 0
#endif
) {
if (info->ce == prepared && PMMPTHREAD_OBJECT_PROPERTY(info)) {
prepared->properties_info_table[OBJ_PROP_TO_NUM(info->offset)] = info;
}
} ZEND_HASH_FOREACH_END();
Expand Down
2 changes: 1 addition & 1 deletion src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void pmmpthread_store_tohash(zend_object *object, HashTable *hash) {

for (int i = 0; i < object->ce->default_properties_count; i++) {
zend_property_info* info = object->ce->properties_info_table[i];
if (info == NULL || (info->flags & ZEND_ACC_STATIC) != 0) {
if (info == NULL || !PMMPTHREAD_OBJECT_PROPERTY(info)) {
continue;
}

Expand Down

0 comments on commit 2d0d49f

Please sign in to comment.