hphp/hack/manual/hsl/Functions/HH.Lib.File/temporary_file.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Create a new temporary file
namespace HH\Lib\File;
function temporary_file(
string $prefix = 'hack-tmp-',
string $suffix = '',
): TemporaryFile;
The file is automatically deleted when the disposable is removed.
., it is interpreted relative to the current
working directory./, it is treated as an absolute path.Regardless of the kind of prefix, the parent directory must exist.
A suffix can optionally be provided; this is useful when you need a
particular filename extension; for example,
File\temporary_file('foo', '.txt') may create /tmp/foo123456.txt.
The temporary file:
O_CREAT | O_EXCL)string $prefix = 'hack-tmp-'string $suffix = ''TemporaryFile