com php-src: Fixed bug #77631: UPGRADING Zend/zend_builtin_ functions.c ext/reflection/tests/ReflectionClass_isSubcla ssOf_error2.phpt
| From: | Nikita Popov | Date: | Tue, 19 Feb 2019 09:07:40 +0000 |
| Subject: | com php-src: Fixed bug #77631: UPGRADING Zend/zend_builtin_ functions.c ext/reflection/tests/ReflectionClass_isSubcla ssOf_error2.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104720@lists.php.net to get a copy of this message | ||
Commit: 12ffee57d6adf38f8dd8b39ea7f7a5e4c462d358
Author: Tyson Andre <tysonandre775@hotmail.com> Mon, 18 Feb 2019 09:35:45 -0500
Committer: Nikita Popov <nikita.ppv@gmail.com> Tue, 19 Feb 2019 10:07:40 +0100
Parents: cdfe11f80d5affd6d5386d84dff0d81323b60bc4
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=12ffee57d6adf38f8dd8b39ea7f7a5e4c462d358
Log:
Fixed bug #77631
Do not include unbound anonymous classes in get_declared_classes().
Note that earlier PHP versions would include the anonymous class in
get_declared_classes(), and return false until the class was bound,
but would not crash.
Bugs:
https://bugs.php.net/77631
Changed paths:
M UPGRADING
M Zend/zend_builtin_functions.c
A ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt
Diff:
diff --git a/UPGRADING b/UPGRADING
index c1a3c19..38c53cc 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -25,6 +25,8 @@ PHP 7.4 UPGRADE NOTES
. Referencing parent:: inside a class that does not have a parent will now
generate a compile-time error. Previously the error was only emitted at
run-time.
+ . get_declared_classes() no longer returns anonymous classes that haven't
+ been instantiated yet.
- Curl:
. Attempting to serialize a CURLFile class will now generate an exception.
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 2b16991..f588229 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1796,7 +1796,8 @@ ZEND_FUNCTION(get_declared_classes)
ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), key, ce) {
if (key
&& ZSTR_VAL(key)[0] != 0
- && !(ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT))) {
+ && !(ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT))
+ && (ce->ce_flags & ZEND_ACC_LINKED)) {
copy_class_or_interface_name(return_value, key, ce);
}
} ZEND_HASH_FOREACH_END();
diff --git a/ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt
b/ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt
new file mode 100644
index 0000000..8671c25
--- /dev/null
+++ b/ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt
@@ -0,0 +1,35 @@
+--TEST--
+ReflectionClass::isSubclassOf() - fixed crash for unbound anonymous class
+--FILE--
+<?php
+class X {
+ public static function main() {
+ return new class() extends Base {};
+ }
+}
+class Base {}
+$check = function () {
+ $base = Base::class;
+ foreach (get_declared_classes() as $class) {
+ if (strpos($class, 'class@anonymous') === false) {
+ continue;
+ }
+ echo "Checking for $class\n";
+ flush();
+ $rc = new ReflectionClass($class);
+ var_export($rc->isSubclassOf($base));
+ echo "\n";
+ }
+};
+// Should not show up in get_declared_classes until the anonymous class is bound.
+$check();
+echo "After first check\n";
+X::main();
+$check();
+echo "Done\n";
+?>
+--EXPECTF--
+After first check
+Checking for class@%s
+true
+Done