Skip to content

Commit 35b4a33

Browse files
committed
Clarify that the get_properties handler is required
Some places were checking for non-null get_properties, some weren't. Make it clear that the handler is required and such checks are not necessary.
1 parent 74d138e commit 35b4a33

File tree

6 files changed

+8
-17
lines changed

6 files changed

+8
-17
lines changed

Zend/zend.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
389389
break;
390390
case IS_OBJECT:
391391
{
392-
HashTable *properties = NULL;
392+
HashTable *properties;
393393
zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
394394
zend_printf("%s Object (", ZSTR_VAL(class_name));
395395
zend_string_release_ex(class_name, 0);
@@ -399,9 +399,7 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
399399
return;
400400
}
401401

402-
if (Z_OBJ_HANDLER_P(expr, get_properties)) {
403-
properties = Z_OBJPROP_P(expr);
404-
}
402+
properties = Z_OBJPROP_P(expr);
405403
if (properties) {
406404
Z_PROTECT_RECURSION_P(expr);
407405
print_flat_hash(properties);

Zend/zend_builtin_functions.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,12 +1174,7 @@ ZEND_FUNCTION(get_object_vars)
11741174
Z_PARAM_OBJECT(obj)
11751175
ZEND_PARSE_PARAMETERS_END();
11761176

1177-
if (Z_OBJ_HT_P(obj)->get_properties == NULL) {
1178-
RETURN_FALSE;
1179-
}
1180-
11811177
properties = Z_OBJ_HT_P(obj)->get_properties(obj);
1182-
11831178
if (properties == NULL) {
11841179
RETURN_FALSE;
11851180
}

Zend/zend_object_handlers.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp) /* {{{ *
145145

146146
if (!ce->__debugInfo) {
147147
*is_temp = 0;
148-
return Z_OBJ_HANDLER_P(object, get_properties)
149-
? Z_OBJ_HANDLER_P(object, get_properties)(object)
150-
: NULL;
148+
return Z_OBJ_HANDLER_P(object, get_properties)(object);
151149
}
152150

153151
zend_call_method_with_0_params(object, ce, &ce->__debugInfo, ZEND_DEBUGINFO_FUNC_NAME, &retval);

Zend/zend_object_handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ struct _zend_object_handlers {
147147
zend_object_unset_property_t unset_property;
148148
zend_object_has_dimension_t has_dimension;
149149
zend_object_unset_dimension_t unset_dimension;
150-
zend_object_get_properties_t get_properties;
150+
zend_object_get_properties_t get_properties; /* required */
151151
zend_object_get_method_t get_method;
152152
zend_object_call_method_t call_method;
153153
zend_object_get_constructor_t get_constructor;

Zend/zend_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
670670
#define Z_OBJPROP(zval) Z_OBJ_HT((zval))->get_properties(&(zval))
671671
#define Z_OBJPROP_P(zval_p) Z_OBJPROP(*(zval_p))
672672

673-
#define Z_OBJDEBUG(zval,tmp) (Z_OBJ_HANDLER((zval),get_debug_info)?Z_OBJ_HANDLER((zval),get_debug_info)(&(zval),&tmp):(tmp=0,Z_OBJ_HANDLER((zval),get_properties)?Z_OBJPROP(zval):NULL))
673+
#define Z_OBJDEBUG(zval,tmp) (Z_OBJ_HANDLER((zval),get_debug_info)?Z_OBJ_HANDLER((zval),get_debug_info)(&(zval),&tmp):(tmp=0,Z_OBJPROP(zval)))
674674
#define Z_OBJDEBUG_P(zval_p,tmp) Z_OBJDEBUG(*(zval_p), tmp)
675675

676676
#define Z_RES(zval) (zval).value.res

ext/reflection/php_reflection.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
434434
}
435435
smart_str_append_printf(str, "%s }\n", indent);
436436

437-
if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) {
437+
if (obj && Z_TYPE_P(obj) == IS_OBJECT) {
438438
HashTable *properties = Z_OBJ_HT_P(obj)->get_properties(obj);
439439
zend_string *prop_name;
440440
smart_str prop_str = {0};
@@ -4322,7 +4322,7 @@ ZEND_METHOD(reflection_class, getProperties)
43224322
_addproperty(prop_info, key, ce, return_value, filter);
43234323
} ZEND_HASH_FOREACH_END();
43244324

4325-
if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT(intern->obj)->get_properties) {
4325+
if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) {
43264326
HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(&intern->obj);
43274327
zval *prop;
43284328
ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) {
@@ -5227,7 +5227,7 @@ ZEND_METHOD(reflection_property, __construct)
52275227
|| ((property_info->flags & ZEND_ACC_PRIVATE)
52285228
&& property_info->ce != ce)) {
52295229
/* Check for dynamic properties */
5230-
if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT && Z_OBJ_HT_P(classname)->get_properties) {
5230+
if (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT) {
52315231
if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name)) {
52325232
dynam_prop = 1;
52335233
}

0 commit comments

Comments
 (0)