diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-23 12:41:24 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-07-24 10:52:01 +0200 |
commit | a49d53baa2ad2fb6a951360f0083a883e7631370 (patch) | |
tree | 320d8ff3021f4bf20540ea553a766865c85e5991 | |
parent | d9680272c78453a832ef02f914efa13c2545eb19 (diff) | |
download | php-git-a49d53baa2ad2fb6a951360f0083a883e7631370.tar.gz |
Don't skip uninitialized typed props in get_class_vars()
For bug #78319.
-rw-r--r-- | Zend/tests/get_class_vars_typed_props.phpt | 26 | ||||
-rw-r--r-- | Zend/zend_builtin_functions.c | 11 |
2 files changed, 34 insertions, 3 deletions
diff --git a/Zend/tests/get_class_vars_typed_props.phpt b/Zend/tests/get_class_vars_typed_props.phpt new file mode 100644 index 0000000000..6e9747265c --- /dev/null +++ b/Zend/tests/get_class_vars_typed_props.phpt @@ -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) +} diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 2d0db8f712..d4718f8d08 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -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 |