]> granicus.if.org Git - php/commitdiff
Implemented FR #78638 (__PHP_Incomplete_Class should be final)
authorXinchen Hui <laruence@gmail.com>
Tue, 24 Dec 2019 09:09:44 +0000 (17:09 +0800)
committerXinchen Hui <laruence@gmail.com>
Tue, 24 Dec 2019 09:09:44 +0000 (17:09 +0800)
This should be minor and won't impact anyone

NEWS
ext/standard/incomplete_class.c
ext/standard/tests/class_object/bug78638.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1ff886df00aba221e4366317cc1c2cc269b35e27..9ab884ee43092f42ffcf48c19a61baeb1f5783df 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -83,6 +83,7 @@ PHP                                                                        NEWS
   . Added SQLite3::setAuthorizer() and respective class constants. (bohwaz)
 
 - Standard:
+  . Implemented FR #78638 (__PHP_Incomplete_Class should be final). (Laruence)
   . Fixed bug #77204 (getimagesize(): Read error! should mention file path).
     (peter279k)
   . Fixed bug #76859 (stream_get_line skips data if used with data-generating
index 5e4c6ca203ee2d0e7c51caac8f4365c9e55232f6..c024373e7d7265decbafe4ba7da9771da8a581c7 100644 (file)
@@ -108,9 +108,10 @@ static zend_object *php_create_incomplete_object(zend_class_entry *class_type)
 
 PHPAPI zend_class_entry *php_create_incomplete_class(void)
 {
-       zend_class_entry incomplete_class;
+       zend_class_entry incomplete_class, *incomplete_class_entry;
 
        INIT_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL);
+
        incomplete_class.create_object = php_create_incomplete_object;
 
        memcpy(&php_incomplete_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
@@ -121,7 +122,10 @@ PHPAPI zend_class_entry *php_create_incomplete_class(void)
        php_incomplete_object_handlers.get_property_ptr_ptr = incomplete_class_get_property_ptr_ptr;
     php_incomplete_object_handlers.get_method = incomplete_class_get_method;
 
-       return zend_register_internal_class(&incomplete_class);
+       incomplete_class_entry = zend_register_internal_class(&incomplete_class);
+       incomplete_class_entry->ce_flags |= ZEND_ACC_FINAL;
+
+       return incomplete_class_entry;
 }
 /* }}} */
 
diff --git a/ext/standard/tests/class_object/bug78638.phpt b/ext/standard/tests/class_object/bug78638.phpt
new file mode 100644 (file)
index 0000000..088e7c4
--- /dev/null
@@ -0,0 +1,9 @@
+--TEST--
+FR: #78638 (__PHP_Incomplete_Class should be final)
+--FILE--
+<?php
+$c = new class('bar') extends __PHP_Incomplete_Class {
+};
+?>
+--EXPECTF--
+Fatal error: Class class@anonymous may not inherit from final class (__PHP_Incomplete_Class) in %sbug78638.php on line %d