PHP 8.5.0 Alpha 4 available for testing

Voting

: five minus zero?
(Example: nine)

The Note You're Voting On

Richard Snell
9 years ago
It is important to note that the mask parameter will accept values other than octal and that this can cause unexpected results.

Setting umask(22) could be expected to reduce a file with default 0666 permission to 0644 by applying a mask of 0022 but as the parameter is being supplied as a decimal it will be converted to octal silently and actually apply a mask of 0026 resulting in a final file permission of 0642.

Similarly the value returned by umask is in decimal format. If you correctly apply a mask using umask(0022) and then query the new setting with umask() it will return a value of 18 (0022 octal is 18 decimal).

In short, when applying permissions it is best to pad the supplied value with zeros to create an octal value (22 becomes 0022) and if you want to analyze the returned value remember to convert it to octal for ease of interpretation.

<< Back to user notes page

To Top