Skip to content

Commit 3262c28

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Also propagate include exceptions in opcache Make url_stats in resolve_path quiet
2 parents 1ff6911 + 22e9f9f commit 3262c28

File tree

3 files changed

+60
-22
lines changed

3 files changed

+60
-22
lines changed

Zend/tests/include_stat_is_quiet.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Stats executed during include path resolution should be silent
3+
--FILE--
4+
<?php
5+
6+
class StreamWrapper {
7+
public function url_stat($path, $flags) {
8+
$path = str_replace('test://', 'file://', $path);
9+
if ($flags & STREAM_URL_STAT_QUIET) {
10+
return @stat($path);
11+
} else {
12+
return stat($path);
13+
}
14+
}
15+
}
16+
17+
stream_wrapper_register('test', StreamWrapper::class);
18+
set_include_path('test://foo:test://bar');
19+
20+
try {
21+
require_once 'doesnt_exist.php';
22+
} catch (Exception $e) {
23+
echo $e->getMessage(), "\n";
24+
}
25+
26+
?>
27+
--EXPECTF--
28+
Warning: require_once(doesnt_exist.php): failed to open stream: No such file or directory in %s on line %d
29+
30+
Fatal error: require_once(): Failed opening required 'doesnt_exist.php' (include_path='test://foo:test://bar') in %s on line %d

ext/opcache/ZendAccelerator.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,11 +1679,13 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl
16791679
if (file_handle->type == ZEND_HANDLE_FILENAME) {
16801680
if (accelerator_orig_zend_stream_open_function(file_handle->filename, file_handle) != SUCCESS) {
16811681
*op_array_p = NULL;
1682-
if (type == ZEND_REQUIRE) {
1683-
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
1684-
zend_bailout();
1685-
} else {
1686-
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
1682+
if (!EG(exception)) {
1683+
if (type == ZEND_REQUIRE) {
1684+
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
1685+
zend_bailout();
1686+
} else {
1687+
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
1688+
}
16871689
}
16881690
return NULL;
16891691
}
@@ -1827,11 +1829,13 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type)
18271829
if (!file_handle->opened_path) {
18281830
if (file_handle->type == ZEND_HANDLE_FILENAME &&
18291831
accelerator_orig_zend_stream_open_function(file_handle->filename, file_handle) == FAILURE) {
1830-
if (type == ZEND_REQUIRE) {
1831-
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
1832-
zend_bailout();
1833-
} else {
1834-
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
1832+
if (!EG(exception)) {
1833+
if (type == ZEND_REQUIRE) {
1834+
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
1835+
zend_bailout();
1836+
} else {
1837+
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
1838+
}
18351839
}
18361840
return NULL;
18371841
}
@@ -1981,11 +1985,13 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
19811985
/* open file to resolve the path */
19821986
if (file_handle->type == ZEND_HANDLE_FILENAME &&
19831987
accelerator_orig_zend_stream_open_function(file_handle->filename, file_handle) == FAILURE) {
1984-
if (type == ZEND_REQUIRE) {
1985-
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
1986-
zend_bailout();
1987-
} else {
1988-
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
1988+
if (!EG(exception)) {
1989+
if (type == ZEND_REQUIRE) {
1990+
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
1991+
zend_bailout();
1992+
} else {
1993+
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
1994+
}
19891995
}
19901996
return NULL;
19911997
}
@@ -2037,11 +2043,13 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
20372043
UNEXPECTED(ZCG(accel_directives).validate_permission) &&
20382044
file_handle->type == ZEND_HANDLE_FILENAME &&
20392045
UNEXPECTED(check_persistent_script_access(persistent_script))) {
2040-
if (type == ZEND_REQUIRE) {
2041-
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
2042-
zend_bailout();
2043-
} else {
2044-
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
2046+
if (!EG(exception)) {
2047+
if (type == ZEND_REQUIRE) {
2048+
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
2049+
zend_bailout();
2050+
} else {
2051+
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
2052+
}
20452053
}
20462054
return NULL;
20472055
}

main/fopen_wrappers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
556556
if (wrapper->wops->url_stat) {
557557
php_stream_statbuf ssb;
558558

559-
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
559+
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL)) {
560560
return zend_string_init(trypath, strlen(trypath), 0);
561561
}
562562
if (EG(exception)) {
@@ -596,7 +596,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
596596
if (wrapper->wops->url_stat) {
597597
php_stream_statbuf ssb;
598598

599-
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
599+
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL)) {
600600
return zend_string_init(trypath, strlen(trypath), 0);
601601
}
602602
if (EG(exception)) {

0 commit comments

Comments
 (0)