PHP 8.5.0 Alpha 1 available for testing

Voting

: one plus one?
(Example: nine)

The Note You're Voting On

malcolm.murphy
9 years ago
Clarification Of "mask & 0777":

The manual's comment "umask() sets PHP's umask to mask & 0777 [...]" is merely implying that the method only affects file permissions, but not special modes such as the setuid, setgid or sticky bits. Curiously, PHP does not actually perform the bitwise operation itself, but instead assumes it will be done by a system call of the same name. On some systems such as OS X, umask effectively sets the umask as mask & 07777, but the extraneous bits are not applicable to subsequent PHP calls like mkdir(). Linux's umask does use 0777. Its manual entry has a comment similar to the PHP one, but with a parenthetical statement that helps explain what it means:

"umask() sets the calling process's file mode creation mask (umask) to mask & 0777 (i.e., only the file permission bits of mask are used) [...]"

The fact that permissions can be determined by inverting a mask using the operation $mask & ~0777 is irrelevant, despite its similar appearance to $mask & 0777. The latter operation instead truncates $mask to the first nine low-order bits (i.e., the three rightmost octal digits [and note that the leading zero for octal notation is not itself a digit]). It does not change the remaining bits.

For example, all of the following calls have the same effect: umask(0022), umask(07022), umask(261650) (decimal value of 0777022), and umask(0b111000010010) (binary notation for 07022).

<< Back to user notes page

To Top