diff --git a/NEWS b/NEWS index 103b778aacf4..8b01cda2e84f 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,10 @@ PHP NEWS - PHPDBG: . Fixed bug GH-16174 (Empty string is an invalid expression for ev). (cmb) +- Reflection: + . Fixed bug GH-15902 (Core dumped in ext/reflection/php_reflection.c). + (DanielEScherzer) + - Session: . Fixed bug GH-16385 (Unexpected null returned by session_set_cookie_params). (nielsdos) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 3faf8ed78681..88ca1cd63424 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -639,13 +639,19 @@ static int format_default_value(smart_str *str, zval *value) { } ZEND_HASH_FOREACH_END(); smart_str_appendc(str, ']'); } else if (Z_TYPE_P(value) == IS_OBJECT) { - /* This branch may only be reached for default properties, which don't support arbitrary objects. */ + /* This branch may only be reached for default properties; show enum names, + or the type of non-enums (GH-15902) */ zend_object *obj = Z_OBJ_P(value); zend_class_entry *class = obj->ce; - ZEND_ASSERT(class->ce_flags & ZEND_ACC_ENUM); - smart_str_append(str, class->name); - smart_str_appends(str, "::"); - smart_str_append(str, Z_STR_P(zend_enum_fetch_case_name(obj))); + if (class->ce_flags & ZEND_ACC_ENUM) { + smart_str_append(str, class->name); + smart_str_appends(str, "::"); + smart_str_append(str, Z_STR_P(zend_enum_fetch_case_name(obj))); + } else { + smart_str_appends(str, "object("); + smart_str_append(str, class->name); + smart_str_appends(str, ")"); + } } else { ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST); zend_string *ast_str = zend_ast_export("", Z_ASTVAL_P(value), ""); @@ -878,7 +884,10 @@ static zval *property_get_default(zend_property_info *prop_info) { ZVAL_DEINDIRECT(prop); return prop; } else { - return &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)]; + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + return &EG(uninitialized_zval); + } + return &CE_DEFAULT_PROPERTIES_TABLE(ce)[OBJ_PROP_TO_NUM(prop_info->offset)]; } } diff --git a/ext/reflection/tests/gh15902/ReflectionClass-callable.phpt b/ext/reflection/tests/gh15902/ReflectionClass-callable.phpt new file mode 100644 index 000000000000..62669554b245 --- /dev/null +++ b/ext/reflection/tests/gh15902/ReflectionClass-callable.phpt @@ -0,0 +1,36 @@ +--TEST-- +ReflectionClass object default property - used to say "callable" +--FILE-- + +--EXPECTF-- +string(%d) "Class [ class C ] { + @@ %sReflectionClass-callable.php %d-%d + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ public stdClass $a = object(stdClass) ] + } + + - Methods [0] { + } +} +" diff --git a/ext/reflection/tests/gh15902/ReflectionClass-class.phpt b/ext/reflection/tests/gh15902/ReflectionClass-class.phpt new file mode 100644 index 000000000000..e95d50123f0f --- /dev/null +++ b/ext/reflection/tests/gh15902/ReflectionClass-class.phpt @@ -0,0 +1,37 @@ +--TEST-- +ReflectionClass object default property - used to say "__CLASS__" +--FILE-- + +--EXPECTF-- +string(%d) "Class [ class C ] { + @@ %sReflectionClass-class.php %d-%d + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [1] { + Property [ public stdClass $a = object(stdClass) ] + } + + - Methods [0] { + } +} +" diff --git a/ext/reflection/tests/gh15902/ReflectionProperty-callable.phpt b/ext/reflection/tests/gh15902/ReflectionProperty-callable.phpt new file mode 100644 index 000000000000..64402f1bfe60 --- /dev/null +++ b/ext/reflection/tests/gh15902/ReflectionProperty-callable.phpt @@ -0,0 +1,19 @@ +--TEST-- +ReflectionProperty object default - used to say "callable" +--FILE-- + +--EXPECTF-- +string(%d) "Property [ public stdClass $a = object(stdClass) ] +" diff --git a/ext/reflection/tests/gh15902/ReflectionProperty-class.phpt b/ext/reflection/tests/gh15902/ReflectionProperty-class.phpt new file mode 100644 index 000000000000..454403f9eeca --- /dev/null +++ b/ext/reflection/tests/gh15902/ReflectionProperty-class.phpt @@ -0,0 +1,19 @@ +--TEST-- +ReflectionProperty object default - used to say "__CLASS__" +--FILE-- + +--EXPECTF-- +string(%d) "Property [ public stdClass $a = object(stdClass) ] +"