umask()

umask() — Changes the current umask.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

umask() sets PHP's umask to mask & 0777 and returns the old umask. When PHP is being used as a server module, the umask is restored when each request is finished.

Signature

umask(?int $mask = null): int

Parameters

ParameterTypeWhat it takes
$mask?intThe new umask.

Return value

If mask is null, umask() simply returns the current umask otherwise the old umask is returned.

Example

A runnable snippet:

$old = umask(0); chmod("/path/some_dir/some_file.txt", 0755); umask($old); // Checking if ($old != umask()) { die('An error occurred while changing back the umask'); }

Changelog

VersionChange
8.0.0mask is nullable now.

All PHP 8.5 built-in functions

Reference card built from the PHP manual page umask() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.