Notice that directory(s) and file(s) sometimes have different results.
<?php
umask(0670); //- set umask
$handle = fopen('file', 'w'); //- 0006
mkdir("/path/dir"); //- 0107
?>
calculate the result:
<?php
$umask = 0670;
umask($umask);
//- if you are creating a new directory, $permission = 0777;
//- if you are creating a new file, $permission = 0666.
printf( "result: %04o", $permission & ( 0777 - $umask) );
?>
BTW, as the manual said, the form of umask() is "int umask ( [int mask] )", so if you want to print/echo any umask, don't forget to convert it from DEC (because it returns a "int") to OCT.
<?php
$umask = umask(); //- returns the current umask, which is a "int"
$umask = decoct($umask); //- Now, $umask is a "string"
echo $umask;
?>
Don't forget that the argument(parameter) is a "int", too.
<?php
umask(777); //- WRONG! Even though you maybe use "umask 777" in some OS.
umask(0777); //- OK
?>
If there was any mistake, please correct my statement.