diff options
| author | Tyson Andre <tysonandre775@hotmail.com> | 2019-02-18 09:35:45 -0500 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-02-19 10:07:40 +0100 |
| commit | 12ffee57d6adf38f8dd8b39ea7f7a5e4c462d358 (patch) | |
| tree | 3aa2352aea809ce81f1f84529d68b175fe791e53 | |
| parent | cdfe11f80d5affd6d5386d84dff0d81323b60bc4 (diff) | |
| download | php-git-12ffee57d6adf38f8dd8b39ea7f7a5e4c462d358.tar.gz | |
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.
| -rw-r--r-- | UPGRADING | 2 | ||||
| -rw-r--r-- | Zend/zend_builtin_functions.c | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt | 35 |
3 files changed, 39 insertions, 1 deletions
@@ -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 2b16991d1c..f588229aff 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 0000000000..8671c2500b --- /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 |
