Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1873,16 +1873,7 @@ ZEND_API void object_properties_load(zend_object *object, const HashTable *prope
static zend_always_inline zend_result _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties) /* {{{ */
{
if (UNEXPECTED(ce->ce_flags & ZEND_ACC_UNINSTANTIABLE)) {
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
zend_throw_error(NULL, "Cannot instantiate interface %s", ZSTR_VAL(ce->name));
} else if (ce->ce_flags & ZEND_ACC_TRAIT) {
zend_throw_error(NULL, "Cannot instantiate trait %s", ZSTR_VAL(ce->name));
} else if (ce->ce_flags & ZEND_ACC_ENUM) {
zend_throw_error(NULL, "Cannot instantiate enum %s", ZSTR_VAL(ce->name));
} else {
ZEND_ASSERT(ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS));
zend_throw_error(NULL, "Cannot instantiate abstract class %s", ZSTR_VAL(ce->name));
}
zend_cannot_instantiate_class(ce);
ZVAL_NULL(arg);
Z_OBJ_P(arg) = NULL;
return FAILURE;
Expand Down
6 changes: 1 addition & 5 deletions Zend/zend_lazy_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,7 @@ ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,

if (!obj) {
if (UNEXPECTED(reflection_ce->ce_flags & ZEND_ACC_UNINSTANTIABLE)) {
zval zobj;
/* Call object_init_ex() for the generated exception */
zend_result result = object_init_ex(&zobj, reflection_ce);
ZEND_ASSERT(result == FAILURE && EG(exception));
(void)result;
zend_cannot_instantiate_class(reflection_ce);
return NULL;
}

Expand Down
15 changes: 15 additions & 0 deletions Zend/zend_objects_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,18 @@ ZEND_API ZEND_COLD zend_property_info *zend_get_property_info_for_slot_slow(zend
} ZEND_HASH_FOREACH_END();
return NULL;
}

ZEND_API ZEND_COLD zend_never_inline void zend_cannot_instantiate_class(
const zend_class_entry *ce
) {
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_UNINSTANTIABLE);
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
zend_throw_error(NULL, "Cannot instantiate interface %s", ZSTR_VAL(ce->name));
} else if (ce->ce_flags & ZEND_ACC_TRAIT) {
zend_throw_error(NULL, "Cannot instantiate trait %s", ZSTR_VAL(ce->name));
} else if (ce->ce_flags & ZEND_ACC_ENUM) {
zend_throw_error(NULL, "Cannot instantiate enum %s", ZSTR_VAL(ce->name));
} else if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
zend_throw_error(NULL, "Cannot instantiate abstract class %s", ZSTR_VAL(ce->name));
}
}
2 changes: 2 additions & 0 deletions Zend/zend_objects_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,6 @@ static zend_always_inline bool zend_check_method_accessible(const zend_function
return true;
}

ZEND_API ZEND_COLD zend_never_inline void zend_cannot_instantiate_class(const zend_class_entry *ce);

#endif /* ZEND_OBJECTS_H */
Loading