Skip to content

Commit cbbf350

Browse files
committed
Fix GH-8176: Fix leaking enum values in property initializers
1 parent 4b90eef commit cbbf350

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.5
44

5+
- Core:
6+
. Fixed bug GH-8176 (Enum values in property initializers leak). (Bob)
7+
58
- Intl:
69
. Fixed bug GH-8115 (Can't catch arg type deprecation when instantiating Intl
710
classes). (ilutov)

Zend/tests/enum/gh8176.phpt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Enum object in property initializer
3+
--FILE--
4+
<?php
5+
6+
class AClass
7+
{
8+
public $prop = AnEnum::Value;
9+
}
10+
11+
enum AnEnum
12+
{
13+
case Value;
14+
}
15+
16+
var_dump(new AClass);
17+
18+
?>
19+
--EXPECT--
20+
object(AClass)#2 (1) {
21+
["prop"]=>
22+
enum(AnEnum::Value)
23+
}

Zend/zend_execute_API.c

+12
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
329329
ZVAL_UNDEF(&c->value);
330330
}
331331
} ZEND_HASH_FOREACH_END();
332+
333+
/* properties may contain objects as well */
334+
if (ce->default_properties_table) {
335+
zval *p = ce->default_properties_table;
336+
zval *end = p + ce->default_properties_count;
337+
338+
while (p != end) {
339+
i_zval_ptr_dtor(p);
340+
ZVAL_UNDEF(p);
341+
p++;
342+
}
343+
}
332344
}
333345

334346
if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {

0 commit comments

Comments
 (0)