Skip to content

Commit ade9d5e

Browse files
committed
Suppress zend_throw_error during preload constant resolution
Related to bug #77615.
1 parent c150079 commit ade9d5e

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

Zend/zend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,11 @@ ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const c
15031503
exception_ce = zend_ce_error;
15041504
}
15051505

1506+
/* Marker used to disable exception generation during preloading. */
1507+
if (EG(exception) == (void*)(uintptr_t)-1) {
1508+
return;
1509+
}
1510+
15061511
va_start(va, format);
15071512
zend_vspprintf(&message, 0, format, va);
15081513

ext/opcache/ZendAccelerator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,11 +3453,11 @@ static void preload_link(void)
34533453
break;
34543454
}
34553455
if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
3456-
zend_error(E_WARNING, "Can't preload unlinked class %s at %s:%d\n", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
3456+
zend_error(E_WARNING, "Can't preload unlinked class %s at %s:%d", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
34573457
} else if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
3458-
zend_error(E_WARNING, "Can't preload class %s with unresolved constants at %s:%d\n", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
3458+
zend_error(E_WARNING, "Can't preload class %s with unresolved constants at %s:%d", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
34593459
} else if (!(ce->ce_flags & ZEND_ACC_PROPERTY_TYPES_RESOLVED)) {
3460-
zend_error(E_WARNING, "Can't preload class %s with unresolved property types at %s:%d\n", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
3460+
zend_error(E_WARNING, "Can't preload class %s with unresolved property types at %s:%d", ZSTR_VAL(ce->name), ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
34613461
} else {
34623462
continue;
34633463
}

ext/opcache/tests/preload_004.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Preloading class with undefined class constant access
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_undef_const.inc
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
var_dump(class_exists('Foo'));
13+
?>
14+
--EXPECTF--
15+
Warning: Can't preload class Foo with unresolved constants at %s:%d in Unknown on line 0
16+
bool(false)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
class Foo {
3+
const A = self::DOES_NOT_EXIST;
4+
}

0 commit comments

Comments
 (0)