Skip to content

Fix #76735: Incorrect message in fopen on invalid mode #6187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/bz2/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ bool(false)
resource(%d) of type (stream)
resource(%d) of type (stream)

Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d
Warning: fopen(bz_open_002.txt): failed to open stream: `br' is not a valid mode for fopen in %s on line %d

Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d
bool(false)

Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d
Warning: fopen(bz_open_002.txt): failed to open stream: `br' is not a valid mode for fopen in %s on line %d

Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d
bool(false)
Expand Down
8 changes: 8 additions & 0 deletions ext/standard/tests/file/bug76735.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
Bug #76735 (Incorrect message in fopen on invalid mode)
--FILE--
<?php
fopen(__FILE__, 'Q');
?>
--EXPECTF--
Warning: fopen(%s): failed to open stream: `Q' is not a valid mode for fopen in %s on line %d
4 changes: 1 addition & 3 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,7 @@ PHPAPI php_stream *_php_stream_fopen(const char *filename, const char *mode, zen
char *persistent_id = NULL;

if (FAILURE == php_stream_parse_fopen_modes(mode, &open_flags)) {
if (options & REPORT_ERRORS) {
php_error_docref(NULL, E_WARNING, "`%s' is not a valid mode for fopen", mode);
}
php_stream_wrapper_log_error(&php_plain_files_wrapper, options, "`%s' is not a valid mode for fopen", mode);
return NULL;
}

Expand Down