Skip to content

Commit efbcbd6

Browse files
committed
Fix dumping of private uninitialized props
By switching to the slot API, which doesn't need unmangled keys and is faster anyway... Also moving those APIs to a place that has a complete prop_info def.
1 parent cfd76b0 commit efbcbd6

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

Zend/zend_object_handlers.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,7 @@ static zend_always_inline zend_property_info *prop_info_for_offset(
634634
if (cache_slot) {
635635
return cache_slot[2];
636636
} else {
637-
zend_property_info *info = zend_get_property_info_for_slot(obj, OBJ_PROP(obj, prop_offset));
638-
return (info && info->type) ? info : NULL;
637+
return zend_get_typed_property_info_for_slot(obj, OBJ_PROP(obj, prop_offset));
639638
}
640639
}
641640

Zend/zend_object_handlers.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,6 @@ ZEND_API HashTable *zend_get_properties_for(zval *obj, zend_prop_purpose purpose
246246
} \
247247
} while (0)
248248

249-
static inline struct _zend_property_info *zend_get_property_info_for_slot(zend_object *obj, zval *slot)
250-
{
251-
struct _zend_property_info **table = obj->ce->properties_info_table;
252-
intptr_t prop_num = slot - obj->properties_table;
253-
ZEND_ASSERT(prop_num >= 0 && prop_num < obj->ce->default_properties_count);
254-
return table[prop_num];
255-
}
256-
257249
#define zend_free_trampoline(func) do { \
258250
if ((func) == &EG(trampoline)) { \
259251
EG(trampoline).common.function_name = NULL; \

Zend/zend_objects_API.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_en
9595
return obj;
9696
}
9797

98+
static inline zend_property_info *zend_get_property_info_for_slot(zend_object *obj, zval *slot)
99+
{
100+
zend_property_info **table = obj->ce->properties_info_table;
101+
intptr_t prop_num = slot - obj->properties_table;
102+
ZEND_ASSERT(prop_num >= 0 && prop_num < obj->ce->default_properties_count);
103+
return table[prop_num];
104+
}
105+
106+
/* Helper for cases where we're only interested in property info of typed properties. */
107+
static inline zend_property_info *zend_get_typed_property_info_for_slot(zend_object *obj, zval *slot)
108+
{
109+
zend_property_info *prop_info = zend_get_property_info_for_slot(obj, slot);
110+
if (prop_info && prop_info->type) {
111+
return prop_info;
112+
}
113+
return NULL;
114+
}
115+
98116

99117
#endif /* ZEND_OBJECTS_H */
100118

Zend/zend_vm_def.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6458,9 +6458,9 @@ ZEND_VM_HANDLER(126, ZEND_FE_FETCH_RW, VAR, ANY, JMP_ADDR)
64586458
if (EXPECTED(value_type != IS_UNDEF)
64596459
&& EXPECTED(zend_check_property_access(Z_OBJ_P(array), p->key, 0) == SUCCESS)) {
64606460
if ((value_type & Z_TYPE_MASK) != IS_REFERENCE) {
6461-
zend_property_info *prop_info = zend_get_property_info_for_slot(
6462-
Z_OBJ_P(array), value);
6463-
if (UNEXPECTED(prop_info && prop_info->type)) {
6461+
zend_property_info *prop_info =
6462+
zend_get_typed_property_info_for_slot(Z_OBJ_P(array), value);
6463+
if (UNEXPECTED(prop_info)) {
64646464
ZVAL_NEW_REF(value, value);
64656465
ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(value), prop_info);
64666466
value_type = IS_REFERENCE_EX;

Zend/zend_vm_execute.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23904,9 +23904,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FE_FETCH_RW_SPEC_VAR_HANDLER(Z
2390423904
if (EXPECTED(value_type != IS_UNDEF)
2390523905
&& EXPECTED(zend_check_property_access(Z_OBJ_P(array), p->key, 0) == SUCCESS)) {
2390623906
if ((value_type & Z_TYPE_MASK) != IS_REFERENCE) {
23907-
zend_property_info *prop_info = zend_get_property_info_for_slot(
23908-
Z_OBJ_P(array), value);
23909-
if (UNEXPECTED(prop_info && prop_info->type)) {
23907+
zend_property_info *prop_info =
23908+
zend_get_typed_property_info_for_slot(Z_OBJ_P(array), value);
23909+
if (UNEXPECTED(prop_info)) {
2391023910
ZVAL_NEW_REF(value, value);
2391123911
ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(value), prop_info);
2391223912
value_type = IS_REFERENCE_EX;

ext/standard/var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
175175
if (Z_TYPE_P(val) == IS_INDIRECT) {
176176
val = Z_INDIRECT_P(val);
177177
if (key) {
178-
prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(struc), key, NULL);
178+
prop_info = zend_get_typed_property_info_for_slot(Z_OBJ_P(struc), val);
179179
}
180180
}
181181

@@ -359,7 +359,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level) /* {{{ */
359359
if (Z_TYPE_P(val) == IS_INDIRECT) {
360360
val = Z_INDIRECT_P(val);
361361
if (key) {
362-
prop_info = zend_object_fetch_property_type_info(Z_OBJCE_P(struc), key, NULL);
362+
prop_info = zend_get_typed_property_info_for_slot(Z_OBJ_P(struc), val);
363363
}
364364
}
365365

0 commit comments

Comments
 (0)