]> granicus.if.org Git - php/commitdiff
Don't skip uninitialized typed props in get_class_vars()
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 23 Jul 2019 10:41:24 +0000 (12:41 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 24 Jul 2019 08:52:01 +0000 (10:52 +0200)
For bug #78319.

Zend/tests/get_class_vars_typed_props.phpt [new file with mode: 0644]
Zend/zend_builtin_functions.c

diff --git a/Zend/tests/get_class_vars_typed_props.phpt b/Zend/tests/get_class_vars_typed_props.phpt
new file mode 100644 (file)
index 0000000..6e97472
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+get_class_vars() returns uninitialized typed properties with a null value
+--FILE--
+<?php
+
+class Test {
+    public static int $int1;
+    public static int $int2 = 42;
+    public int $int3;
+    public int $int4 = 42;
+}
+
+var_dump(get_class_vars(Test::class));
+
+?>
+--EXPECT--
+array(4) {
+  ["int3"]=>
+  NULL
+  ["int4"]=>
+  int(42)
+  ["int1"]=>
+  NULL
+  ["int2"]=>
+  int(42)
+}
index 2d0db8f7126b74d49e889c5bd5b73cd2aa61bc51..d4718f8d08e28a20cd3988efc5efc4182cc698c3 100644 (file)
@@ -1123,12 +1123,17 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int st
                } else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
                        prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
                }
-               if (!prop || Z_TYPE_P(prop) == IS_UNDEF) {
+               if (!prop) {
                        continue;
                }
 
-               /* copy: enforce read only access */
-               ZVAL_COPY_OR_DUP(&prop_copy, prop);
+               if (Z_ISUNDEF_P(prop)) {
+                       /* Return uninitialized typed properties as a null value */
+                       ZVAL_NULL(&prop_copy);
+               } else {
+                       /* copy: enforce read only access */
+                       ZVAL_COPY_OR_DUP(&prop_copy, prop);
+               }
                prop = &prop_copy;
 
                /* this is necessary to make it able to work with default array