8000 Clear recorded errors before executing shutdown functions · php/php-src@52b5c15 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52b5c15

Browse files
committed
Clear recorded errors before executing shutdown functions
Recorded errors may be attached to the wrong cached script when a fatal error occurs during recording. This happens because the fatal error will cause a bailout, which may prevent the recorded errors from being freed. If an other script is compiled after bailout, or if a class is linked after bailout, the recorded errors will be attached to it. This change fixes this by freeing recorded errors before executing shutdown functions. Fixes GH-8063
1 parent ec0771c commit 52b5c15

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

ext/opcache/tests/bug8297.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #8297 (Opcache breaks autoloading after E_COMPILE_ERROR)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
--EXTENSIONS--
7+
opcache
8+
--FILE--
9+
<?php
10+
11+
spl_autoload_register(function ($class) {
12+
printf("Autoloading %s\n", $class);
13+
include __DIR__.DIRECTORY_SEPARATOR.'bug8297'.DIRECTORY_SEPARATOR.$class.'.inc';
14+
});
15+
16+
register_shutdown_function(function () {
17+
new Bar();
18+
new Baz();
19+
print "Finished\n";
20+
});
21+
22+
new BadClass();
23+
--EXPECTF--
24+
Autoloading BadClass
25+
Autoloading Foo
26+
27+
Fatal error: Declaration of BadClass::dummy() must be compatible with Foo::dummy(): void in %sBadClass.inc on line 5
28+
Autoloading Bar
29+
Autoloading Baz
30+
Finished
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
class BadClass extends Foo
4+
{
5+
function dummy()
6+
{
7+
}
8+
}

ext/opcache/tests/bug8297/Bar.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
class Bar {}

ext/opcache/tests/bug8297/Baz.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
class Baz {}

ext/opcache/tests/bug8297/Foo.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
function dummy(): void
6+
{
7+
}
8+
}

ext/standard/basic_functions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,11 @@ static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_
17671767
PHPAPI void php_call_shutdown_functions(void) /* {{{ */
17681768
{
17691769
if (BG(user_shutdown_function_names)) {
1770+
if (EG(record_errors)) {
1771+
zend_free_recorded_errors();
1772+
EG(record_errors) = false;
1773+
}
1774+
17701775
zend_try {
17711776
zend_hash_apply(BG(user_shutdown_function_names), user_shutdown_function_call);
17721777
} zend_end_try();

0 commit comments

Comments
 (0)
0