echo "ok\n";
?>
--EXPECTF--
-Fatal error: Interface RecurisiveFooFar cannot implement itself in %sbug30922.php on line %d
+Fatal error: Interface 'RecurisiveFooFar' not found in %sbug30922.php on line %d
--- /dev/null
+--TEST--
+Classes can only be used once they are fully linked
+--FILE--
+<?php
+
+spl_autoload_register(function($class) {
+ echo new ReflectionClass(A::class), "\n";
+});
+
+class A implements I {
+}
+
+?>
+--EXPECTF--
+Fatal error: During class fetch: Uncaught ReflectionException: Class A does not exist in %s:%d
+Stack trace:
+#0 %s(%d): ReflectionClass->__construct('A')
+#1 [internal function]: {closure}('I')
+#2 %s(%d): spl_autoload_call('I')
+#3 {main} in %s on line %d
/* Children must reuse parent get_iterator() | | | */
#define ZEND_ACC_REUSE_GET_ITERATOR (1 << 18) /* X | | | */
/* | | | */
+/* Class is being linked. Don't free strings. | | | */
+#define ZEND_ACC_LINKING_IN_PROGRESS (1 << 19) /* X | | | */
+/* | | | */
/* Function Flags (unused: 28...30) | | | */
/* ============== | | | */
/* | | | */
if (!key) {
zend_string_release_ex(lc_name, 0);
}
- return (zend_class_entry*)Z_PTR_P(zv);
+ ce = (zend_class_entry*)Z_PTR_P(zv);
+ if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_LINKED))) {
+ return NULL;
+ }
+ return ce;
}
/* The compiler is not-reentrant. Make sure we __autoload() only during run-time
ZEND_API void zend_do_link_class(zend_class_entry *ce, zend_class_entry *parent) /* {{{ */
{
- ce->ce_flags |= ZEND_ACC_LINKED;
+ ce->ce_flags |= ZEND_ACC_LINKING_IN_PROGRESS;
if (parent) {
zend_do_inheritance(ce, parent);
}
}
zend_build_properties_info_table(ce);
+ ce->ce_flags &= ~ZEND_ACC_LINKING_IN_PROGRESS;
+ ce->ce_flags |= ZEND_ACC_LINKED;
}
/* }}} */
return SUCCESS;
}
if (class_type->num_interfaces) {
- ZEND_ASSERT(class_type->ce_flags & ZEND_ACC_LINKED);
+ ZEND_ASSERT(class_type->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_LINKING_IN_PROGRESS));
for (i = 0; i < class_type->num_interfaces; i++) {
if (class_type->interfaces[i] == zend_ce_aggregate || class_type->interfaces[i] == zend_ce_iterator) {
return SUCCESS;
} else if (class_type->get_iterator != zend_user_it_get_new_iterator) {
/* c-level get_iterator cannot be changed (exception being only Traversable is implemented) */
if (class_type->num_interfaces) {
- ZEND_ASSERT(class_type->ce_flags & ZEND_ACC_LINKED);
+ ZEND_ASSERT(class_type->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_LINKING_IN_PROGRESS));
for (i = 0; i < class_type->num_interfaces; i++) {
if (class_type->interfaces[i] == zend_ce_iterator) {
zend_error_noreturn(E_ERROR, "Class %s cannot implement both %s and %s at the same time",
}
switch (ce->type) {
case ZEND_USER_CLASS:
- if (ce->parent_name && !(ce->ce_flags & ZEND_ACC_LINKED)) {
+ if (ce->parent_name && !(ce->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_LINKING_IN_PROGRESS))) {
zend_string_release_ex(ce->parent_name, 0);
}
if (ce->default_properties_table) {
}
zend_hash_destroy(&ce->constants_table);
if (ce->num_interfaces > 0) {
- if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
+ if (!(ce->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_LINKING_IN_PROGRESS))) {
uint32_t i;
for (i = 0; i < ce->num_interfaces; i++) {