Skip to content

Commit d9ff09a

Browse files
committed
Extract code for reporting a zend_fetch_class() error
1 parent 25b0906 commit d9ff09a

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

Zend/zend_execute_API.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,28 @@ void zend_unset_timeout(void) /* {{{ */
14791479
}
14801480
/* }}} */
14811481

1482+
static ZEND_COLD void report_class_fetch_error(zend_string *class_name, int fetch_type)
1483+
{
1484+
if (fetch_type & ZEND_FETCH_CLASS_SILENT) {
1485+
return;
1486+
}
1487+
1488+
if (EG(exception)) {
1489+
if (!(fetch_type & ZEND_FETCH_CLASS_EXCEPTION)) {
1490+
zend_exception_uncaught_error("During class fetch");
1491+
}
1492+
return;
1493+
}
1494+
1495+
if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
1496+
zend_throw_or_error(fetch_type, NULL, "Interface \"%s\" not found", ZSTR_VAL(class_name));
1497+
} else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
1498+
zend_throw_or_error(fetch_type, NULL, "Trait \"%s\" not found", ZSTR_VAL(class_name));
1499+
} else {
1500+
zend_throw_or_error(fetch_type, NULL, "Class \"%s\" not found", ZSTR_VAL(class_name));
1501+
}
1502+
}
1503+
14821504
zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {{{ */
14831505
{
14841506
zend_class_entry *ce, *scope;
@@ -1520,15 +1542,7 @@ zend_class_entry *zend_fetch_class(zend_string *class_name, int fetch_type) /* {
15201542

15211543
ce = zend_lookup_class_ex(class_name, NULL, fetch_type);
15221544
if (!ce) {
1523-
if (!(fetch_type & ZEND_FETCH_CLASS_SILENT) && !EG(exception)) {
1524-
if (fetch_sub_type == ZEND_FETCH_CLASS_INTERFACE) {
1525-
zend_throw_or_error(fetch_type, NULL, "Interface \"%s\" not found", ZSTR_VAL(class_name));
1526-
} else if (fetch_sub_type == ZEND_FETCH_CLASS_TRAIT) {
1527-
zend_throw_or_error(fetch_type, NULL, "Trait \"%s\" not found", ZSTR_VAL(class_name));
1528-
} else {
1529-
zend_throw_or_error(fetch_type, NULL, "Class \"%s\" not found", ZSTR_VAL(class_name));
1530-
}
1531-
}
1545+
report_class_fetch_error(class_name, fetch_type);
15321546
return NULL;
15331547
}
15341548
return ce;
@@ -1539,22 +1553,7 @@ zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, zend_string
15391553
{
15401554
zend_class_entry *ce = zend_lookup_class_ex(class_name, key, fetch_type);
15411555
if (!ce) {
1542-
if (fetch_type & ZEND_FETCH_CLASS_SILENT) {
1543-
return NULL;
1544-
}
1545-
if (EG(exception)) {
1546-
if (!(fetch_type & ZEND_FETCH_CLASS_EXCEPTION)) {
1547-
zend_exception_uncaught_error("During class fetch");
1548-
}
1549-
return NULL;
1550-
}
1551-
if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) {
1552-
zend_throw_or_error(fetch_type, NULL, "Interface \"%s\" not found", ZSTR_VAL(class_name));
1553-
} else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) {
1554-
zend_throw_or_error(fetch_type, NULL, "Trait \"%s\" not found", ZSTR_VAL(class_name));
1555-
} else {
1556-
zend_throw_or_error(fetch_type, NULL, "Class \"%s\" not found", ZSTR_VAL(class_name));
1557-
}
1556+
report_class_fetch_error(class_name, fetch_type);
15581557
return NULL;
15591558
}
15601559
return ce;

0 commit comments

Comments
 (0)