Fix GH-8176: Fix leaking enum values in property initializers

This commit is contained in:
Bob Weinand 2022-03-07 03:53:38 +01:00
parent 4b90eef9cf
commit cbbf3502a2
3 changed files with 38 additions and 0 deletions

3
NEWS
View File

@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.5
- Core:
. Fixed bug GH-8176 (Enum values in property initializers leak). (Bob)
- Intl:
. Fixed bug GH-8115 (Can't catch arg type deprecation when instantiating Intl
classes). (ilutov)

View File

@ -0,0 +1,23 @@
--TEST--
Enum object in property initializer
--FILE--
<?php
class AClass
{
public $prop = AnEnum::Value;
}
enum AnEnum
{
case Value;
}
var_dump(new AClass);
?>
--EXPECT--
object(AClass)#2 (1) {
["prop"]=>
enum(AnEnum::Value)
}

View File

@ -329,6 +329,18 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
ZVAL_UNDEF(&c->value);
}
} ZEND_HASH_FOREACH_END();
/* properties may contain objects as well */
if (ce->default_properties_table) {
zval *p = ce->default_properties_table;
zval *end = p + ce->default_properties_count;
while (p != end) {
i_zval_ptr_dtor(p);
ZVAL_UNDEF(p);
p++;
}
}
}
if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {