As already mentioned, there is no octal type. And the chmod function gets the second parameter as an integer. The implicit conversion of $perm does not imply that the number is octal. Thus, you need to convert the "octal string" to an integer using the appropriate function.
Just use the octdec function
$perm = "0777"; //this is fetch from the database chmod("myFolder/", octdec($perm));
Or intval
chmod("myFolder/", intval($perm, 8));
PS
var_dump('0644' == 0644); // bool(false) var_dump(intval('0644') == 0644); // bool(false) var_dump(decoct('0644') == 0644); // bool(false) var_dump(octdec('0644') == 0644); // bool(true) var_dump(intval('0644', 8) == 0644); // bool(true)
source share