Skip to content
Open
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
2 changes: 0 additions & 2 deletions ext/standard/tests/file/bug52624.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ echo tempnam("directory_that_not_exists", "prefix_");

?>
--EXPECTF--
Notice: tempnam(): file created in the system's temporary directory in %sbug52624.php on line %d

Warning: tempnam(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
2 changes: 0 additions & 2 deletions ext/standard/tests/file/tempnam_variation3-win32.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ OK
-- Iteration 3 --
OK
-- Iteration 4 --

Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation3-win32.php on line %d
Failed, not created in the correct directory %s vs %s
0
-- Iteration 5 --
Expand Down
14 changes: 10 additions & 4 deletions main/php_open_temporary_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,16 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin
if (temp_dir &&
*temp_dir != '\0' &&
(!(flags & PHP_TMP_FILE_OPEN_BASEDIR_CHECK_ON_FALLBACK) || !php_check_open_basedir(temp_dir))) {
return php_do_open_temporary_file(temp_dir, pfx, opened_path_p);
fd = php_do_open_temporary_file(temp_dir, pfx, opened_path_p);
if (!(flags & PHP_TMP_FILE_SILENT) && dir && *dir != '\0') {
/* Default temporary directory fallback. */
if (UNEXPECTED(fd == -1)) {
/* TODO: decide whether we should notice that even the fallback failed? */
} else {
Comment on lines +309 to +311
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked and all callers trigger their own warning if the function fails so I think you should remove this TODO. Also if we really wanted such warning / notice, it should happen for non fallback as well...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see what you meant of keep that message after reading Tim's comment. I guess maybe that makes sense to add a noticed so people don't get confused actually.

php_error_docref(NULL, E_NOTICE, "file created in the system's temporary directory");
}
}
return fd;
} else {
return -1;
}
Expand All @@ -317,9 +326,6 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin
fd = php_do_open_temporary_file(dir, pfx, opened_path_p);
if (fd == -1) {
/* Use default temporary directory. */
if (!(flags & PHP_TMP_FILE_SILENT)) {
php_error_docref(NULL, E_NOTICE, "file created in the system's temporary directory");
Copy link
Member

@TimWolla TimWolla Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively perhaps just:

file will be created […]

Looking at ext/standard/tests/file/bug52624.phpt folks might otherwise be confused why the final error message mentions /tmp.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. I'm undecided yet, hence also the TODO I put

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should change the text completely (even for successful fallback creation) because some people can ignore error message by text in error handler (I saw that in some legacy code in past) so we don't want to break that (or more minimise chance of breaking it) if the target is 8.3. But different message in that TODO bit would make sense.

}
goto def_tmp;
}
return fd;
Expand Down
Loading