Skip to content

Commit 003be87

Browse files
committed
Make url_stats in resolve_path quiet
These stats are used to check whether the file exists -- they should not generate errors. Having the flag set is particularly important for custom stream wrappers.
1 parent 98df5c9 commit 003be87

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
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

main/fopen_wrappers.c

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

561-
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, 0, &ssb, NULL)) {
561+
if (SUCCESS == wrapper->wops->url_stat(wrapper, trypath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL)) {
562562
return zend_string_init(trypath, strlen(trypath), 0);
563563
}
564564
if (EG(exception)) {
@@ -598,7 +598,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
598598
if (wrapper->wops->url_stat) {
599599
php_stream_statbuf ssb;
600600

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

0 commit comments

Comments
 (0)