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.
. 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.
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();
--- /dev/null
+--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