Skip to content

Commit 236ddc5

Browse files
committed
Preserve original ce_flags when registering class
Bug that regularly sneaks in: ZEND_ACC_FINAL is set before calling zend_register_internal_class() and promptly gets ignored. Remove this footgun by preserving flags from the original CE.
1 parent 777aa91 commit 236ddc5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class
25772577

25782578
class_entry->type = ZEND_INTERNAL_CLASS;
25792579
zend_initialize_class_data(class_entry, 0);
2580-
class_entry->ce_flags = ce_flags | ZEND_ACC_CONSTANTS_UPDATED | ZEND_ACC_LINKED | ZEND_ACC_RESOLVED_PARENT | ZEND_ACC_RESOLVED_INTERFACES;
2580+
class_entry->ce_flags = orig_class_entry->ce_flags | ce_flags | ZEND_ACC_CONSTANTS_UPDATED | ZEND_ACC_LINKED | ZEND_ACC_RESOLVED_PARENT | ZEND_ACC_RESOLVED_INTERFACES;
25812581
class_entry->info.internal.module = EG(current_module);
25822582

25832583
if (class_entry->info.internal.builtin_functions) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Check that ReflectionAttribute is final
3+
--FILE--
4+
<?php
5+
6+
class T extends ReflectionAttribute {}
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Class T may not inherit from final class (ReflectionAttribute) in %s on line %d

0 commit comments

Comments
 (0)