Edit report at https://bugs.php.net/bug.php?id=60847&edit=1

 ID:                 60847
 Comment by:         phpmpan at mpan dot pl
 Reported by:        me at davecarlson dot co dot uk
 Summary:            mkdir second argument should prepend leading zero if
                     only 3 numbers are inputte
 Status:             Open
 Type:               Feature/Change Request
 Package:            *Directory/Filesystem functions
 Operating System:   Debian Squeeze
 PHP Version:        5.3.9
 Block user comment: N
 Private report:     N

 New Comment:

There is no way to detect this, as this is a function, not a language 
construct. Also the argument may come from a variable or another function.

You are also missing one important thing: there is NO requirement to use 
leading zero. `mkdir` accepts a bitmask. A convenient way to input bitmasks is 
hexadecimal or octal notation. This way of describing numbers is used in many 
cases, not only to specify file mode mask. But this is just a way to specify a 
number, nothing more. If you want, you can safely write 493 or 0x1ED an 
everything will be OK. If one doesn't feel comfortable with specifying bitmasks 
directly, something more explicit may be used:
(1 << 9 | 1 << 8 | 1 << 7 | 1 << 6 | 1 << 4 | 1 << 3 | 1)


Previous Comments:
------------------------------------------------------------------------
[2012-01-23 10:36:27] me at davecarlson dot co dot uk

Description:
------------
---
>From manual page: http://www.php.net/function.mkdir#refsect1-function.mkdir-
parameters
---

It can be **very** easy to omit the leading zero in the permissions argument, 
especially if working on a command line all day where "775" for example works 
in 
a chmod. Although the documentation clearly states it needs a leading zero, it 
would be good if the function could detect such a trivial error that can lead 
to 
quite bad results. It would also help consistency between the linux command 
line 
and php.

Test script:
---------------
<?php

mkdir("/tmp/test", 775); // This should be recognised as 0775 are only 3 
characters specified

 


Expected result:
----------------
I expect the permissions to be set as "rwxrwxr-x"

Actual result:
--------------
The permissions are actually set as "r-----r-t"


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60847&edit=1

Reply via email to