php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60847 mkdir second argument should prepend leading zero if only 3 numbers are inputte
Submitted: 2012-01-23 10:36 UTC Modified: 2012-01-24 12:12 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: me at davecarlson dot co dot uk Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.3.9 OS: Debian Squeeze
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: me at davecarlson dot co dot uk
New email:
PHP Version: OS:

 

 [2012-01-23 10:36 UTC] 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"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-23 20:47 UTC] phpmpan at mpan dot pl
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)
 [2012-01-24 12:12 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2012-01-24 12:12 UTC] cataphract@php.net
Bogus as this is unfeasible.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC