]> granicus.if.org Git - php/commitdiff
Clarify that the get_properties handler is required
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 4 Oct 2018 08:56:43 +0000 (10:56 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 4 Oct 2018 10:46:50 +0000 (12:46 +0200)
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.

Zend/zend.c
Zend/zend_builtin_functions.c
Zend/zend_object_handlers.c
Zend/zend_object_handlers.h
Zend/zend_types.h
ext/reflection/php_reflection.c

index 6a53e60aa1fdb45ecd69701221c89bc7381185e2..ee88afed02e60d70af19eaa31986f9067a5c54df 100644 (file)
@@ -389,7 +389,7 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
                        break;
                case IS_OBJECT:
                {
-                       HashTable *properties = NULL;
+                       HashTable *properties;
                        zend_string *class_name = Z_OBJ_HANDLER_P(expr, get_class_name)(Z_OBJ_P(expr));
                        zend_printf("%s Object (", ZSTR_VAL(class_name));
                        zend_string_release_ex(class_name, 0);
@@ -399,9 +399,7 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
                                return;
                        }
 
-                       if (Z_OBJ_HANDLER_P(expr, get_properties)) {
-                               properties = Z_OBJPROP_P(expr);
-                       }
+                       properties = Z_OBJPROP_P(expr);
                        if (properties) {
                                Z_PROTECT_RECURSION_P(expr);
                                print_flat_hash(properties);
index 586b9d4e7fd766165e18acf27eb8fb55819cf55a..f68388cd208dd41c971d67814332a63bbe32b6d0 100644 (file)
@@ -1174,12 +1174,7 @@ ZEND_FUNCTION(get_object_vars)
                Z_PARAM_OBJECT(obj)
        ZEND_PARSE_PARAMETERS_END();
 
-       if (Z_OBJ_HT_P(obj)->get_properties == NULL) {
-               RETURN_FALSE;
-       }
-
        properties = Z_OBJ_HT_P(obj)->get_properties(obj);
-
        if (properties == NULL) {
                RETURN_FALSE;
        }
index f56913cbe830288a5896431c904959db8395ebfb..96395a755421f79089b0094a98b77f8b6ef0de56 100644 (file)
@@ -145,9 +145,7 @@ ZEND_API HashTable *zend_std_get_debug_info(zval *object, int *is_temp) /* {{{ *
 
        if (!ce->__debugInfo) {
                *is_temp = 0;
-               return Z_OBJ_HANDLER_P(object, get_properties)
-                       ? Z_OBJ_HANDLER_P(object, get_properties)(object)
-                       : NULL;
+               return Z_OBJ_HANDLER_P(object, get_properties)(object);
        }
 
        zend_call_method_with_0_params(object, ce, &ce->__debugInfo, ZEND_DEBUGINFO_FUNC_NAME, &retval);
index 9437aaaf762f59c42563e898222b36427dceb5ab..094489a80ccd2ddcde8b4fbcc40a965319220c9b 100644 (file)
@@ -147,7 +147,7 @@ struct _zend_object_handlers {
        zend_object_unset_property_t                    unset_property;
        zend_object_has_dimension_t                             has_dimension;
        zend_object_unset_dimension_t                   unset_dimension;
-       zend_object_get_properties_t                    get_properties;
+       zend_object_get_properties_t                    get_properties; /* required */
        zend_object_get_method_t                                get_method;
        zend_object_call_method_t                               call_method;
        zend_object_get_constructor_t                   get_constructor;
index 64f8dee295bea3035b4a8171a8ff35862a6bc28c..2e773df6e96c500602fc7b86f5d527dc11c2bcd4 100644 (file)
@@ -670,7 +670,7 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
 #define Z_OBJPROP(zval)                                Z_OBJ_HT((zval))->get_properties(&(zval))
 #define Z_OBJPROP_P(zval_p)                    Z_OBJPROP(*(zval_p))
 
-#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))
+#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)))
 #define Z_OBJDEBUG_P(zval_p,tmp)       Z_OBJDEBUG(*(zval_p), tmp)
 
 #define Z_RES(zval)                                    (zval).value.res
index 4838b5cebc9ab34b2c6db987034e5c331504e2cc..8114625e6839f6cae5a304b4b75c9a4107cbbd84 100644 (file)
@@ -434,7 +434,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
        }
        smart_str_append_printf(str, "%s  }\n", indent);
 
-       if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_properties) {
+       if (obj && Z_TYPE_P(obj) == IS_OBJECT) {
                HashTable    *properties = Z_OBJ_HT_P(obj)->get_properties(obj);
                zend_string  *prop_name;
                smart_str prop_str = {0};
@@ -4322,7 +4322,7 @@ ZEND_METHOD(reflection_class, getProperties)
                _addproperty(prop_info, key, ce, return_value, filter);
        } ZEND_HASH_FOREACH_END();
 
-       if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0 && Z_OBJ_HT(intern->obj)->get_properties) {
+       if (Z_TYPE(intern->obj) != IS_UNDEF && (filter & ZEND_ACC_PUBLIC) != 0) {
                HashTable *properties = Z_OBJ_HT(intern->obj)->get_properties(&intern->obj);
                zval *prop;
                ZEND_HASH_FOREACH_STR_KEY_VAL(properties, key, prop) {
@@ -5227,7 +5227,7 @@ ZEND_METHOD(reflection_property, __construct)
         || ((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 (property_info == NULL && Z_TYPE_P(classname) == IS_OBJECT) {
                        if (zend_hash_exists(Z_OBJ_HT_P(classname)->get_properties(classname), name)) {
                                dynam_prop = 1;
                        }