Skip to content

Commit

Permalink
Preserve original ce_flags when registering class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Jul 20, 2020
1 parent 777aa91 commit 236ddc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,7 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class

class_entry->type = ZEND_INTERNAL_CLASS;
zend_initialize_class_data(class_entry, 0);
class_entry->ce_flags = ce_flags | ZEND_ACC_CONSTANTS_UPDATED | ZEND_ACC_LINKED | ZEND_ACC_RESOLVED_PARENT | ZEND_ACC_RESOLVED_INTERFACES;
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;
class_entry->info.internal.module = EG(current_module);

if (class_entry->info.internal.builtin_functions) {
Expand Down
10 changes: 10 additions & 0 deletions ext/reflection/tests/ReflectionAttribute_final.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Check that ReflectionAttribute is final
--FILE--
<?php

class T extends ReflectionAttribute {}

?>
--EXPECTF--
Fatal error: Class T may not inherit from final class (ReflectionAttribute) in %s on line %d

0 comments on commit 236ddc5

Please sign in to comment.